I was trying to save multiple cards of a customer by creating a customer payment profile for each card using the customer profile id. The code is working fine as it is creating a profile at first and then it is returning a duplicate error as given below.
Response
{
"success": false,
"message": "A duplicate customer payment profile already exists.",
"error": {
"status": false,
"message": "A duplicate customer payment profile already exists.",
"data": ""
}
}
https://developer.authorize.net/api/reference/features/customer_profiles.html
Code
createCustomerPaymentProfile: async payload => {
const {
businessData,
customerProfileId,
customerDetails,
creditCardDetails,
} = payload;
const merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();
merchantAuthenticationType.setName(businessData.apiLoginKey);
merchantAuthenticationType.setTransactionKey(businessData.transactionKey);
const creditCard = new ApiContracts.CreditCardType();
creditCard.setCardNumber(creditCardDetails.CardNumber);
creditCard.setExpirationDate(creditCardDetails.ExpirationDate);
const paymentType = new ApiContracts.PaymentType();
paymentType.setCreditCard(creditCard);
const customerAddress = new ApiContracts.CustomerAddressType();
customerAddress.setFirstName(customerDetails.FirstName);
customerAddress.setLastName(customerDetails.LastName);
customerAddress.setAddress(customerDetails.Address);
customerAddress.setCity(customerDetails.FirstName);
customerAddress.setState(customerDetails.FirstName);
customerAddress.setZip(customerDetails.FirstName);
customerAddress.setCountry(customerDetails.FirstName);
customerAddress.setPhoneNumber(customerDetails.FirstName);
const profile = new ApiContracts.CustomerPaymentProfileType();
profile.setBillTo(customerAddress);
profile.setPayment(paymentType);
const createRequest = new ApiContracts.CreateCustomerPaymentProfileRequest();
createRequest.setMerchantAuthentication(merchantAuthenticationType);
createRequest.setCustomerProfileId(customerProfileId);
createRequest.setPaymentProfile(profile);
const ctrl = new ApiControllers.CreateCustomerPaymentProfileController(
createRequest.getJSON(),
);
const result = await new Promise((resolve, reject) => {
ctrl.execute(function() {
const apiResponse = ctrl.getResponse();
const response = new ApiContracts.CreateCustomerPaymentProfileResponse(
apiResponse,
);
console.log('Response of Pyament Profile');
console.log(JSON.stringify(response, null, 2));
if (response != null) {
if (
response.getMessages().getResultCode() ==
ApiContracts.MessageTypeEnum.OK
) {
return resolve({
status: true,
message: 'Customer paymentProfileId,customerProfileId ',
data: {
paymentProfileId: response.getCustomerPaymentProfileId(),
customerProfileId: response.getCustomerProfileId(),
},
});
}
return reject({
status: false,
message: `${response
.getMessages()
.getMessage()[0]
.getText()}`,
data: '',
});
}
return reject({
status: false,
message: `Null response returned`,
data: '',
});
});
});
return result;
}
I had this error in transactions and subscription API's but those were fixed by adding the code given below.
const transactionSetting1 = new ApiContracts.SettingType();
transactionSetting1.setSettingName('duplicateWindow');
transactionSetting1.setSettingValue('0');
How can I add multiple cards to authorize.net? Is there any settings object to allow duplicate payment profile. ?