Sample Code: Submit Payment With Tokenization

Generating a Token

To generate a token, submit a payment transactions as described here: Sample Code: Submit Payment

Modify the above code to include the following in the formulatePaymentRequest() method:

payment.fw1__Create_Token__c = true;
payment.fw1__Account__c = <ACCOUNT ID>; // optional if contact exists
payment.fw1__Contact__c = <CONTACT ID>; // optional if account exists

After submitting the transaction, a payment record will be created and will have the generated token in the Token field (fw1__Payment__c.fw1__Token__c):

You can then save that token in a custom field in the Account or Contact object.

Using the Token

To use the token generated above, submit a payment transaction as described here: Sample Code: Submit Payment

Modify the code to remove the credit card information and replace them with the token. In the formulatePaymentRequest() method, remove the following:

payment.fw1__Credit_Card_Type__c = 'Visa';
payment.fw1__First_Name__c = 'Joe';
payment.fw1__Last_Name__c = 'Smith';
payment.fw1__Credit_Card_Number__c = '4111111111111111';
payment.fw1__Expiry_Month__c = '01';
payment.fw1__Expiry_Year__c = '2018';
payment.fw1__Billing_Street__c = '12345 sepulveda st';
payment.fw1__Billing_City__c = 'Torrance';
payment.fw1__Billing_State__c = 'CA';
payment.fw1__Billing_Zip__c = '90505';
payment.fw1__Billing_Country__c = 'US';
payment.fw1__Create_Token__c = true;

In the same formulatePaymentRequest() method, add the following:

payment.fw1__Token__c = <YOUR TOKEN>;