cancel
Showing results for 
Search instead for 
Did you mean: 

How to set customerProfileId in transaction request obj of GetHostedPaymentPageRequest in nodejs ?

I am trying to implement accept.js in react node.js 

 

I want to send customerProfileId in node with the request as shown in this demo API reference  JSON request

but am not able to understand how can I do that.

 

I have tried with the below code to send customerProfileId

 

 

const fetchFormToken = (amount) => {
  const merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();
  merchantAuthenticationType.setName("************");
  merchantAuthenticationType.setTransactionKey("**************");

  const transactionRequestType = new ApiContracts.TransactionRequestType();
  transactionRequestType.setTransactionType(
    ApiContracts.TransactionTypeEnum.AUTHCAPTURETRANSACTION
  );

  var customerProfileIdType = new ApiContracts.CustomerProfileIdType();
  customerProfileIdType.setCustomerProfileId('***********');
  console.log(customerProfileIdType);

  transactionRequestType.setAmount(amount);
  transactionRequestType.setCustomer('*************');
  transactionRequestType.profile(customerProfileIdType)
console.log(transactionRequestType)
  const setting1 = new ApiContracts.SettingType();
  setting1.setSettingName('hostedPaymentButtonOptions');
  setting1.setSettingValue('{"text": "Pay"}');

  const setting2 = new ApiContracts.SettingType();
  setting2.setSettingName('hostedPaymentOrderOptions');
  setting2.setSettingValue('{"show": false}');

  const setting3 = new ApiContracts.SettingType();
  setting3.setSettingName('hostedPaymentIFrameCommunicatorUrl');
  setting3.setSettingValue(`{"url": "https://localhost:3000/iFrameCommunicator.html"}`);

  const setting4 = new ApiContracts.SettingType();
  setting4.setSettingName('hostedPaymentReturnOptions');
  setting4.setSettingValue(
    '{"showReceipt": true, "url": "https://localhost:3000?receipt=true", "urlText": "Continue", "cancelUrl": "https://localhost:3000?cancel=true", "cancelUrlText": "Cancel"}'
  );
  // var setting5 = new ApiContracts.SettingType();
  // setting5.setSettingName('hostedPaymentPaymentOptions');
  // setting5.setSettingValue(`{"cardCodeRequired": true, "showCreditCard": true}`);


  const settingList = [];
  settingList.push(setting1);
  settingList.push(setting2);
  settingList.push(setting3);
  settingList.push(setting4);
  // settingList.push(setting5);

  const alist = new ApiContracts.ArrayOfSetting();
  alist.setSetting(settingList);

  const getRequest = new ApiContracts.GetHostedPaymentPageRequest();
  getRequest.setMerchantAuthentication(merchantAuthenticationType);
  getRequest.setTransactionRequest(transactionRequestType);
  getRequest.setHostedPaymentSettings(alist);

  const ctrl = new ApiControllers.GetHostedPaymentPageController(
    getRequest.getJSON()
  );
  return new Promise((resolve, reject) => {
    ctrl.execute(function () {
      const apiResponse = ctrl.getResponse();

      const response = new ApiContracts.GetHostedPaymentPageResponse(
        apiResponse
      );

      if (response != null) {
        if (
          response.getMessages().getResultCode() ===
          ApiContracts.MessageTypeEnum.OK
        ) {
          resolve(response.getToken());
        } 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()
          );
          reject(response.getMessages().getMessage()[0].getText());
        }
      } else {
        reject('Null response received');
      }
    });
  });
};

Result of TransactionRequestType object

 

TransactionRequestType {
  transactionType: 'authCaptureTransaction',
  amount: 50,
  currencyCode: null,
  payment: null,
  profile: CustomerProfileIdType {
    customerProfileId: '502904307',
    customerPaymentProfileId: null,
    customerAddressId: null
  },
  solution: null,
  callId: null,
  terminalNumber: null,
  authCode: null,
  refTransId: null,
  splitTenderId: null,
  order: null,
  lineItems: null,
  tax: null,
  duty: null,
  shipping: null,
  taxExempt: null,
  poNumber: null,
  customer: '903253984',
  billTo: null,
  shipTo: null,
  customerIP: null,
  cardholderAuthentication: null,
  retail: null,
  employeeId: null,
  transactionSettings: null,
  userFields: null,
  surcharge: null,
  merchantDescriptor: null,
  subMerchant: null,
  tip: null,
  processingOptions: null,
  subsequentAuthInformation: null,
  otherTax: null,
  shipFrom: null,
  authorizationIndicatorType: null
}

 

ShreeHariji
Member
0 REPLIES 0