BankPaymentMethodRequest Class

Sends data related to a bank payment method to a gateway adapter during a service call.

Namespace

CommercePayments

Usage

Use the BankPaymentMethodRequest class to include bank payment details in a Tokenize request. The gateway adapter reads the fields from this class when constructing the tokenized JSON request for the payment gateway. You can create an instance of this class by calling bankPaymentMethod on the PaymentMethodTokenizationRequest class.

Example

1private String buildTokenizationRequest(commercepayments.PaymentMethodTokenizationRequest tokenizeRequest) {
2    commercepayments.BankPaymentMethodRequest bankPaymentMethod = tokenizeRequest.bankPaymentMethod;
3
4    // Setup currency
5    String currencyIso = UserInfo.getDefaultCurrency();
6
7    String accountId;
8    JSONGenerator jsonGeneratorInstance = JSON.createGenerator(true);
9    jsonGeneratorInstance.writeStartObject();
10
11    // Basic fields
12    jsonGeneratorInstance.writeStringField('merchantAccount', '{!$Credential.Username}');
13    jsonGeneratorInstance.writeStringField('reference', 'Tokenize_' + String.valueOf(Datetime.now().getTime()));
14
15    // Payment method details (from encrypted form input)
16    jsonGeneratorInstance.writeFieldName('paymentMethod');
17    jsonGeneratorInstance.writeStartObject();
18
19    if (bankPaymentMethod != null) {
20        accountId = bankPaymentMethod.accountId;
21        if (bankPaymentMethod.bankType.equals(commercepayments.BankType.Ach)) {
22            currencyIso = 'USD';
23            jsonGeneratorInstance.writeStringField('type', 'ach');
24            jsonGeneratorInstance.writeStringField('bankAccountNumber', bankPaymentMethod.accountNumber);
25            jsonGeneratorInstance.writeStringField('bankLocationId', bankPaymentMethod.bankCode);
26            jsonGeneratorInstance.writeStringField('ownerName', bankPaymentMethod.accountHolderName);
27
28        } else if (bankPaymentMethod.bankType.equals(commercepayments.BankType.SepaDebit)) {
29
30            currencyIso = 'EUR';
31            jsonGeneratorInstance.writeStringField('type', 'sepadirectdebit');
32            jsonGeneratorInstance.writeStringField('iban', bankPaymentMethod.accountNumber);
33            jsonGeneratorInstance.writeStringField('ownerName', bankPaymentMethod.accountHolderName);
34
35        } else if (bankPaymentMethod.bankType.equals(commercepayments.BankType.Bacs)) {
36
37            currencyIso = 'GBP';
38            jsonGeneratorInstance.writeStringField('type', 'directdebit_GB');
39            jsonGeneratorInstance.writeStringField('bankAccountNumber', bankPaymentMethod.accountNumber);
40            jsonGeneratorInstance.writeStringField('bankLocationId', bankPaymentMethod.bankCode);
41            jsonGeneratorInstance.writeStringField('holderName', bankPaymentMethod.accountHolderName);
42
43        } else if (bankPaymentMethod.bankType.equals(commercepayments.BankType.Becs)) {
44
45            currencyIso = 'AUD';
46            jsonGeneratorInstance.writeStringField('type', 'directdebit_AU');
47            jsonGeneratorInstance.writeStringField('bankAccountNumber', bankPaymentMethod.accountNumber);
48            jsonGeneratorInstance.writeStringField('bsb', bankPaymentMethod.bankCode);
49            jsonGeneratorInstance.writeStringField('ownerName', bankPaymentMethod.accountHolderName);
50
51        } else {
52            //Add support for other banks if required in future.
53        }
54
55        jsonGeneratorInstance.writeEndObject();
56    }
57
58    // Zero-dollar amount
59    jsonGeneratorInstance.writeFieldName('amount');
60    jsonGeneratorInstance.writeStartObject();
61    jsonGeneratorInstance.writeNumberField('value', 0);
62    jsonGeneratorInstance.writeStringField('currency', currencyIso);
63    jsonGeneratorInstance.writeEndObject();
64
65    // Save payment method for later
66    jsonGeneratorInstance.writeStringField('shopperReference', accountId);
67    jsonGeneratorInstance.writeBooleanField('storePaymentMethod', true);
68    jsonGeneratorInstance.writeStringField('shopperInteraction', 'Ecommerce');
69    jsonGeneratorInstance.writeStringField('recurringProcessingModel', 'UnscheduledCardOnFile');
70
71    commercepayments.AddressRequest billingAddress = tokenizeRequest.address;
72
73    if (billingAddress != null) {
74        jsonGeneratorInstance.writeFieldName('billingAddress');
75        jsonGeneratorInstance.writeStartObject();
76        jsonGeneratorInstance.writeStringField('street', billingAddress.street);
77        jsonGeneratorInstance.writeStringField('stateOrProvince', billingAddress.state);
78        jsonGeneratorInstance.writeStringField('city', billingAddress.city);
79        jsonGeneratorInstance.writeStringField('postalCode', billingAddress.postalCode);
80        jsonGeneratorInstance.writeStringField('country', billingAddress.country);
81        jsonGeneratorInstance.writeEndObject();
82
83    }
84    jsonGeneratorInstance.writeEndObject();
85    return jsonGeneratorInstance.getAsString();
86}

BankPaymentMethodRequest Properties

The following are properties for BankPaymentMethodRequest.

accountHolderFirstName

The first name of the account holder for the bank payment method.

Signature

public String accountHolderFirstName {get; set;}

Property Value

Type: String

accountHolderLastName

The last name of the account holder for the bank payment method.

Signature

public String accountHolderLastName {get; set;}

Property Value

Type: String

accountHolderName

The name of the account holder for the bank payment method.

Signature

public String accountHolderName {get; set;}

Property Value

Type: String

accountHolderType

The type of the account holder.

Signature

public commercepayments.AccountHolderType accountHolderType {get; set;}

Property Value

Type: commercepayments.AccountHolderType

accountId

Salesforce Payments account ID associated with the bank payment method.

Signature

public String accountId {get; set;}

Property Value

Type: String

accountNumber

The unique account number for the bank account.

Signature

public String accountNumber {get; set;}

Property Value

Type: String

accountType

The type for the bank account.

Signature

public commercepayments.AccountType accountType {get; set;}

Property Value

Type: commercepayments.AccountType

autoPay

Indicates whether a token for recurring payments is being requested (true) or not (false). The token enables the payment method to be used for recurring payments.

Signature

public Boolean autoPay {get; set;}

Property Value

Type: Boolean

bankCode

The routing number is a unique nine-digit code that identifies the bank.

Signature

public String bankCode {get; set;}

Property Value

Type: String

bankType

The bank type associated with the bank payment method.

Signature

public commercepayments.BankType bankType {get; set;}

Property Value

Type: commercepayments.BankType

comments

Additional details about the bank account.

Signature

public String comments {get; set;}

Property Value

Type: String

email

The email address of the bank account holder.

Signature

public String email {get; set;}

Property Value

Type: String

mandate

Authorization from the account holder to debit their payment method.

Signature

public String mandate {get; set;}

Property Value

Type: String

nickName

The nick name of the account holder.

Signature

public String nickName {get; set;}

Property Value

Type: String

standardEntryClassCode

The three-letter code that identifies the type of electronic payment transaction being processed within the Automated Clearing House (ACH) network.

Signature

public commercepayments.StandardEntryClassCode standardEntryClassCode {get; set;}

Property Value

Type: commercepayments.StandardEntryClassCode

BankPaymentMethodRequest Methods

The following are methods for BankPaymentMethodRequest.

equals(obj)

Maintains the integrity of lists of type BankPaymentMethodRequest by determining the equality of external objects in a list. This method is dynamic and based on the equals method in Java.

Signature

public Boolean equals(Object obj)

Parameters

obj
Type: Object
External object whose key is to be validated.

Return Value

Type: Boolean

hashCode()

Maintains the integrity of lists of type BankPaymentMethodRequest.

Signature

public Integer hashCode()

Return Value

Type: Integer

toString()

Converts a date to a string.

Signature

public String toString()

Return Value

Type: String