Skip to main content

Payment Method Tokenization

Overview

Payment Method Tokenization is the exchange of payment data for a token representation provided by the payment gateway for PCI Compliance. This is an initial step in the payments lifecycle.

Prerequisites

There is one prerequisite resource that must be created before creating a Payment Method Tokenization.

           Object           Definition
Payment GatewayPayment Gateways track all the configuration settings that Chargent will use to proccess the payments and send requests to the gateway.

Create Methods

There are four methods for creating payment methods and tokens.

MethodDefinition
Create Payment MethodCreate a new Payment Method Tokenization with the Payment Gateway.
Import Payment Method TokensImport existing tokens with a Payment Gateway into Chargent.
Multiple Gateway TokenizationCreate multiple Payment Method Tokenizations across multiple MIDs or multiple Payment Gateways.
Headless TokenizationCreate Payment Method Tokenizations without storing response data in Salesforce.

Picklist Values

The following values may be sent for the picklist types.

PicklistValues
paymentMethodTypeCredit Card Bank Account
cardTypeVisa, Mastercard, Discover, American Express, MC Eurocard, UK Maestro, JCB Card, Diners Card
bankAccountTypeChecking, Savings, Business Checking

Create Payment Method

Resource URL

HTTP RequestURL
POST/services/apexrest/ChargentBase/payments/payment-methods

Credit Card

Request

JSON Example
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
}

Response

JSON Example
{
"paymentMethod": {
"tokens": [
{
"token": "47444425",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"id": "{{logId}}",
"gatewayResultCode": "200",
"createdDate": "2023-09-18T21:34:43.131Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-09-18T21:34:43.131Z",
"gatewayAvsCode": ""
}
}

Bank Account

Request

JSON Example
{
"address": { // optional
"companyName": "Salesforce",
"street": "415 Mission St.",
"state": "CA",
"postalcode": "94105",
"country": "US",
"city": "San Francisco"
},
"bankAccountPaymentMethod": {
"bankAccountType": "Checking",
"bankInstitutionName": "{{$randomBankAccountName}}",
"bankAccountNumber": "{{bankAccountNumber}}",
"routingNumber": "{{routingNumber}}",
"bankAccountHolderName": "Chargent Test",
"bankAccountHolderLastName": "Test",
"bankAccountHolderFirstName": "Chargent",
"nickName": "Chargent Test's Business Checking"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
}

Response

JSON Example
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T21:44:44.881Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T21:44:44.882Z"
}
}

Payment Method List

Request

JSON Example
[
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
},
{
"address": { // optional
"companyName": "Salesforce",
"street": "415 Mission St.",
"state": "CA",
"postalcode": "94105",
"country": "US",
"city": "San Francisco"
},
"bankAccountPaymentMethod": {
"bankAccountType": "Checking",
"bankInstitutionName": "{{$randomBankAccountName}}",
"bankAccountNumber": "{{bankAccountNumber}}",
"routingNumber": "{{routingNumber}}",
"bankAccountHolderName": "Chargent Test",
"bankAccountHolderLastName": "Test",
"bankAccountHolderFirstName": "Chargent",
"nickName": "Chargent Test's Business Checking"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
}
]

Response

JSON Example
[
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T21:52:48.625Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T21:52:48.625Z"
}
},
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T21:52:48.625Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T21:52:48.625Z"
}
}
]

JSForce Example

Node.js Example
function createPaymentMethod(conn, iterationNumber, gatewayId) {

const relativeUrl = "/services/apexrest/ChargentBase/payments/payment-methods"

var paymentMethod = {
address: {
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
cardPaymentMethod: {
"cardCategory": "CreditCard",
"cardHolderFirstName": `Chargent ${iterationNumber}`,
"cardHolderLastName": `Test ${iterationNumber}`,
"cardHolderName": `Chargent Test ${iterationNumber}`,
"cardNumber": "{{cardNum}}",
"cardType": "Visa",
"cvv": "123",
"expiryMonth": "12",
"expiryYear": "25",
"nickName": `Nickname ${iterationNumber}`
},
paymentGatewayId: gatewayId,
phone: "{{phoneNumber}}",
email: "{{emailAddress}}"
}
console.log(JSON.stringify(paymentMethod))

return new Promise((resolve, reject) => {
conn.request({
method: 'POST',
url: relativeUrl,
body: JSON.stringify(paymentMethod),
headers: { 'Content-Type': 'application/json' }
}, function(error, result) {
if (error) {
reject(error)
} else {
resolve(result)
}
})
})
}

module.exports = createPaymentMethod

Import Payment Method Tokens

Resource URL

HTTP RequestURL
POST/services/apexrest/ChargentBase/payments/payment-methods/tokens

Request List

JSON Example
[
{
"cardPaymentMethod": {
"cardPaymentMethodName": "Braintree Credit Card",
"paymentMethodType": "Credit Card",
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardType": "Visa",
"cardExpirationMonth": "12",
"cardExpirationYear": "2025",
"cardLast4": "1234",
"company": "Salesforce",
"nickName": "Chargent Test's Business Visa",
"billing": {
"billingAddress": "415 Mission St.",
"billingCity": "San Francisco",
"billingCountry": "US",
"billingEmail": "{{emailAddress}}",
"billingPhone": "123-456-7890",
"billingState": "California",
"billingPostalCode": "94105"
},
"token" : {
"token": "{{token}}",
"paymentGatewayId" : "{{gatewayId}}"
}
}
},
{
"bankAccountPaymentMethod": {
"bankAccountPaymentMethodName": "Braintree Bank Account",
"paymentMethodType": "Bank Account",
"bankAccountHolderFirstName": "Chargent",
"bankAccountHolderLastName": "Test",
"bankAccountHolderName": "Chargent Test",
"routingNumber": "123456789",
"accountLast4": "1234",
"bankAccountType": "Checking",
"bankAccountValidatedOn": "2023-05-30T18:25:43.511Z",
"bankInstitutionName": "{{bankName}}",
"company": "Salesforce",
"billing": {
"billingAddress": "415 Mission St.",
"billingCity": "San Francisco",
"billingCountry": "US",
"billingEmail": "{{emailAddress}}",
"billingPhone": "123-456-7890",
"billingState": "California",
"billingPostalCode": "94105"
},
"token" : {
"token": "{{token}}",
"paymentGatewayId" : "{{gatewayId}}"
}
}
},
{
"cardPaymentMethod": {
"cardPaymentMethodName": "Cybersource Credit Card",
"paymentMethodType": "Credit Card",
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardType": "Visa",
"cardExpirationMonth": "12",
"cardExpirationYear": "2025",
"cardLast4": "1234",
"company": "Salesforce",
"nickName": "Chargent Test's Personal Visa",
"billing": {
"billingAddress": "415 Mission St.",
"billingCity": "San Francisco",
"billingCountry": "US",
"billingEmail": "{{emailAddress}}",
"billingPhone": "123-456-7890",
"billingState": "California",
"billingPostalCode": "94105"
},
"token" : {
"token": "{{token}}",
"paymentGatewayId" : "{{gatewayId2}}"
}
}
}
]

Response List

JSON Example
{
"paymentMethodsResponse": {
"totalSuccess": 3,
"totalErrors": 0,
"records": [
{
"tokenId": "{{token}}",
"message": "Braintree Credit Card was created;",
"id": "{{paymentMethodId}}"
},
{
"tokenId": "{{token}}",
"message": "Braintree Bank Account was created;",
"id": "{{paymentMethodId}}"
},
{
"tokenId": "{{token}}",
"message": "Cybersource Credit Card was created;",
"id": "{{paymentMethodId}}"
}
],
"message": "Imported payment methods successfully"
}
}

Multiple Gateway Tokenization

Resource URL

HTTP RequestURL
POST/services/apexrest/ChargentBase/payments/payment-methods

Request

JSON Example
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "MGT Test",
"cardHolderName": "Chargent MGT Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent MGT Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"multipleTokenization": true,
"paymentGatewayIds": ["{{gatewayId2}}", "{{gatewayId3}}", "{{gatewayId4}}"],
"phone": "{{$randomPhoneNumber}}", //optional
"email": "{{$randomEmail}}" //optional
}

Response

JSON Example
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
},
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
},
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
},
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:35:08.588Z"
},
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "201",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:35:08.588Z"
},
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "100",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:35:08.588Z"
},
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:35:08.588Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T23:35:08.588Z"
}
}

Request List

JSON Example
[
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "MGT Test",
"cardHolderName": "Chargent MGT Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent MGT Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"multipleTokenization": true,
"paymentGatewayIds": ["{{gatewayId2}}"],
"phone": "{{$randomPhoneNumber}}", //optional
"email": "{{$randomEmail}}" //optional
},
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "MGT Test",
"cardHolderName": "Chargent MGT Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent MGT Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"multipleTokenization": true,
"paymentGatewayIds": ["{{gatewayId2}}"],
"phone": "{{$randomPhoneNumber}}", //optional
"email": "{{$randomEmail}}" //optional
}
]

Response List

JSON Example
[
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
},
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:40:20.309Z"
},
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:40:20.309Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T23:40:20.310Z"
}
},
{
"paymentMethod": {
"tokens": [
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
},
{
"token": "{{token}}",
"id": "{{tokenId}}",
"gatewayId": "{{gatewayId}}"
}
],
"status": "Created",
"id": "{{paymentMethodId}}"
},
"logs": [
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayId": "{{gatewayId}}",
"createdDate": "2023-12-06T23:40:20.310Z"
},
{
"interactionStatus": "APPROVED",
"id": "{{logId}}",
"gatewayResultCode": "200",
"gatewayId": "{{gatewayid}}",
"createdDate": "2023-12-06T23:40:20.310Z"
}
],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-06T23:40:20.310Z"
}
}
]

Headless Tokenization

HTTP Header

HTTP HeaderValue
Chargent-Headlesstrue

Headless Create Payment Method

Request

JSON Example
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
}

Response

JSON Example
{
"logs": [],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...",
"gatewayDate": "2023-12-07T00:12:54.139Z"
}
}

Headless Create Payment Method List

Request
JSON Example
[
{
"address": { // optional
"city": "San Francisco",
"companyName": "Salesforce",
"country": "US",
"postalcode": "94105",
"state": "California",
"street": "415 Mission St."
},
"cardPaymentMethod": {
"cardHolderFirstName": "Chargent",
"cardHolderLastName": "Test",
"cardHolderName": "Chargent Test",
"cardNumber": "{{cardNumber}}",
"cardType": "{{cardType}}",
"cvv": "{{cvv}}",
"expiryMonth": "{{expiryMonth}}",
"expiryYear": "{{expiryYear}}",
"nickName": "Chargent Test's Business Visa"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
},
{
"address": {
"companyName": "Salesforce",
"street": "415 Mission St.",
"state": "CA",
"postalcode": "94105",
"country": "US",
"city": "San Francisco"
},
"bankAccountPaymentMethod": {
"bankAccountType": "Checking",
"bankInstitutionName": "{{$randomBankAccountName}}",
"bankAccountNumber": "{{bankAccountNumber}}",
"routingNumber": "{{routingNumber}}",
"bankAccountHolderName": "Chargent Test",
"bankAccountHolderLastName": "Test",
"bankAccountHolderFirstName": "Chargent",
"nickName": "Chargent Test's Business Checking"
},
"paymentGatewayId": "{{gatewayId}}",
"phone": "{{$randomPhoneNumber}}", // optional
"email": "{{$randomEmail}}" // optional
}
]
Response
JSON Example
[
{
"logs": [],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-07T00:18:31.700Z"
}
},
{
"logs": [],
"gatewayResponse": {
"gatewayToken": "{{token}}",
"gatewayResultCodeDescription": "",
"gatewayResultCode": "200",
"gatewayMessage": "{...}",
"gatewayDate": "2023-12-07T00:18:31.701Z"
}
}
]