I am using CyberSource and here is what I am trying to do:
make payment with PAN (customer initialed transaction)
store payment for future use
use stored payment method for merchant initiated transactions
Documentation I used: https://developer.cybersource.com/docs/cybs/en-us/payments/developer/ctv/rest/payments/credentials-p.... Particularly looking at following sections of the documentation:
Initial CIT Recurring Payment with a PAN
Subsequent MIT Recurring Payments
I believe, I follow documentation closely, however, the result that I get is not ideal. First transaction is successful, and it looks like payment method is stored on file. However, following merchant initiated transactions fail with following error: The credit card number is either missing or invalid
Below is my implementation, I am using C# and CyberSource's SDK. I would appreciate any help, thanks you in advance!
CIT (first transaction)
string clientReferenceInformationCode = Guid.NewGuid().ToString();
Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation(
Code: clientReferenceInformationCode
);
bool processingInformationCapture = true;
string processingInformationPaymentSolution = "012";
Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation(
Capture: processingInformationCapture,
PaymentSolution: processingInformationPaymentSolution,
AuthorizationOptions: new Ptsv2paymentsProcessingInformationAuthorizationOptions
{
Initiator = new Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiator
{
CredentialStoredOnFile = true,
Type = "customer"
},
},
CommerceIndicator: "internet"
, RecurringOptions: new Ptsv2paymentsProcessingInformationRecurringOptions
{
FirstRecurringPayment = true
}
) ;
Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation(
FluidData: new Ptsv2paymentsPaymentInformationFluidData
{
Value = googlePayToken,
}
);
string orderInformationAmountDetailsTotalAmount = "1";
string orderInformationAmountDetailsCurrency = "USD";
Ptsv2paymentsOrderInformationAmountDetails orderInformationAmountDetails = new Ptsv2paymentsOrderInformationAmountDetails(
TotalAmount: orderInformationAmountDetailsTotalAmount,
Currency: orderInformationAmountDetailsCurrency
);
string orderInformationBillToFirstName = "John";
string orderInformationBillToLastName = "Deo";
string orderInformationBillToAddress1 = "901 Metro Center Blvd";
string orderInformationBillToLocality = "Foster City";
string orderInformationBillToAdministrativeArea = "CA";
string orderInformationBillToPostalCode = "94404";
string orderInformationBillToCountry = "US";
string orderInformationBillToEmail = "test@googlepay.com";
string orderInformationBillToPhoneNumber = "6504327113";
Ptsv2paymentsOrderInformationBillTo orderInformationBillTo = new Ptsv2paymentsOrderInformationBillTo(
FirstName: orderInformationBillToFirstName,
LastName: orderInformationBillToLastName,
Address1: orderInformationBillToAddress1,
Locality: orderInformationBillToLocality,
AdministrativeArea: orderInformationBillToAdministrativeArea,
PostalCode: orderInformationBillToPostalCode,
Country: orderInformationBillToCountry,
Email: orderInformationBillToEmail,
PhoneNumber: orderInformationBillToPhoneNumber
);
Ptsv2paymentsOrderInformation orderInformation = new Ptsv2paymentsOrderInformation(
AmountDetails: orderInformationAmountDetails,
BillTo: orderInformationBillTo
);
var requestObj = new CreatePaymentRequest(
ClientReferenceInformation: clientReferenceInformation,
ProcessingInformation: processingInformation,
PaymentInformation: paymentInformation,
OrderInformation: orderInformation
);
try
{
var configDictionary = new Configuration().GetConfiguration();
var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
var apiInstance = new PaymentsApi(clientConfig);
PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj);
Console.WriteLine(result);
return result;
}
catch (Exception e)
{
Console.WriteLine("Exception on calling the API : " + e.Message);
return null;
}
Following MITs:
Ptsv2paymentsProcessingInformation processingInformation = new Ptsv2paymentsProcessingInformation(
AuthorizationOptions: new Ptsv2paymentsProcessingInformationAuthorizationOptions
{
Initiator = new Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiator
{
StoredCredentialUsed = true,
Type = "merchant",
MerchantInitiatedTransaction = new Ptsv2paymentsProcessingInformationAuthorizationOptionsInitiatorMerchantInitiatedTransaction
{
Reason = "7",
PreviousTransactionId = transactionId,
}
},
},
CommerceIndicator: "recurring",
Capture: true
);
Ptsv2paymentsPaymentInformation paymentInformation = new Ptsv2paymentsPaymentInformation(
Card: new Ptsv2paymentsPaymentInformationCard
{
ExpirationYear = card.ExpirationYear,
ExpirationMonth = card.ExpirationMonth,
Number = card.Prefix + "xxxxxxxxxxxx"
}
);
string clientReferenceInformationCode = Guid.NewGuid().ToString();
Ptsv2paymentsClientReferenceInformation clientReferenceInformation = new Ptsv2paymentsClientReferenceInformation(
Code: clientReferenceInformationCode
);
var requestObj = new CreatePaymentRequest(
ClientReferenceInformation: clientReferenceInformation,
ProcessingInformation: processingInformation,
OrderInformation: orderInformation,
PaymentInformation: paymentInformation
);
PtsV2PaymentsPost201Response result = apiInstance.CreatePayment(requestObj);
08-29-2023 01:05 AM