0

I'm new to authorize net. Created an API to create a customer in authorize.net using this doc link]

I have added my code below. In this case, the customer is getting created fine and the card details are also getting saved. But now I want the same customer to be able to add another card to their account. I want it to be done in node js. But I can't find a code for that in node.js in their doc. Can anyone help me with this? Thanks in advance.

This is the code I used

    async createCustomerProfile(callback) {
    console.log('id =====', process.env.AUTHORIZE_LOGIN_ID)

    var merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();
    merchantAuthenticationType.setName(process.env.AUTHORIZE_LOGIN_ID);
    merchantAuthenticationType.setTransactionKey(process.env.AUTHORIZE_TRANSACTION_KEY);

    var creditCard = new ApiContracts.CreditCardType();
    creditCard.setCardNumber('4111111111111111');
    creditCard.setExpirationDate('0823');

    var paymentType = new ApiContracts.PaymentType();
    paymentType.setCreditCard(creditCard);

    var customerAddress = new ApiContracts.CustomerAddressType();
    customerAddress.setFirstName('test');
    customerAddress.setLastName('scenario');
    customerAddress.setAddress('123 Main Street');
    customerAddress.setCity('Bellevue');
    customerAddress.setState('WA');
    customerAddress.setZip('98004');
    customerAddress.setCountry('USA');
    customerAddress.setPhoneNumber('000-000-0000');

    var customerPaymentProfileType = new ApiContracts.CustomerPaymentProfileType();
    customerPaymentProfileType.setCustomerType(ApiContracts.CustomerTypeEnum.INDIVIDUAL);
    customerPaymentProfileType.setPayment(paymentType);
    customerPaymentProfileType.setBillTo(customerAddress);

    var paymentProfilesList = [];
    paymentProfilesList.push(customerPaymentProfileType);

    var customerProfileType = new ApiContracts.CustomerProfileType();
    customerProfileType.setMerchantCustomerId('MP_test');
    customerProfileType.setDescription('Profile description here');
    customerProfileType.setEmail('george.h9497@gmail.com');
    customerProfileType.setPaymentProfiles(paymentProfilesList);

    var createRequest = new ApiContracts.CreateCustomerProfileRequest();
    createRequest.setProfile(customerProfileType);
    createRequest.setValidationMode(ApiContracts.ValidationModeEnum.TESTMODE);
    createRequest.setMerchantAuthentication(merchantAuthenticationType);

    //pretty print request
    //console.log(JSON.stringify(createRequest.getJSON(), null, 2));


    var ctrl = new ApiControllers.CreateCustomerProfileController(createRequest.getJSON());

    ctrl.execute(function () {

        var apiResponse = ctrl.getResponse();

        var response = new ApiContracts.CreateCustomerProfileResponse(apiResponse);

        //pretty print response
        //console.log(JSON.stringify(response, null, 2));

        if (response != null) {
            if (response.getMessages().getResultCode() == ApiContracts.MessageTypeEnum.OK) {
                console.log('Successfully created a customer profile with id: ' + response.getCustomerProfileId());
            }
            else {
                console.log('Result Code: ' + response.getMessages().getResultCode());
                console.log('Error Code: ' + response.getMessages().getMessage()[0].getCode());
                console.log('Error message: ' + response.getMessages().getMessage()[0].getText());
            }
        }
        else {
            console.log('Null response received');
        }
        console.log('response ===============', response)
        callback(response);
    });
},
Haris George
  • 291
  • 5
  • 16
  • What part are you stuck on? – Evert May 20 '23 at 18:09
  • @Evert I have a customer with card details in authorize.net. But now I want to add another card also for the same user. Is there a code for that in nodeJS? – Haris George May 20 '23 at 18:10
  • 1
    No, there's no code for that in Node.js. You need to write the code. – Evert May 20 '23 at 18:15
  • @Evert How? Do you have any reference code? – Haris George May 23 '23 at 10:09
  • Are you hoping you find something you can copy paste and tweak? Your question sounds a bit like: "I've tried nothing and I'm all out of ideas". Try writing some code and if you get stuck somewhere maybe you have a more specific question. – Evert May 23 '23 at 17:45

0 Answers0