<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic E00114 - &amp;quot;Invalid OTS Token.&amp;quot; in Node, but works through the API Live Console in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/69820#M42773</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;Using Accept.js to get opaque data which is then used on a Node server to create a subscription.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem: &lt;/STRONG&gt;Everytime I get an&amp;nbsp;"Invalid OTS Token." response, but if I try the exact same JSON request at&amp;nbsp;&lt;A href="https://developer.authorize.net/api/reference/index.html#recurring-billing-create-a-subscription" target="_blank"&gt;https://developer.authorize.net/api/reference/index.html#recurring-billing-create-a-subscription&lt;/A&gt;, then it succeeds.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt; What could be the problem? I assume it's not the payload, nor that it's sent multiple times as it works the second time in the API live console. But what else could it be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;PRE&gt;function createSubscription(req, res) {
  const { opaqueDataDescriptor, opaqueDataValue } = req.body;

  const merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();

  merchantAuthenticationType.setName(config.authorizeNet.loginId);
  merchantAuthenticationType.setTransactionKey(config.authorizeNet.transactionKey);

  const interval = new ApiContracts.PaymentScheduleType.Interval();

  interval.setLength(3);
  interval.setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS);

  const paymentScheduleType = new ApiContracts.PaymentScheduleType();

  paymentScheduleType.setInterval(interval);
  paymentScheduleType.setStartDate((new Date()).toISOString().substring(0, 10));
  paymentScheduleType.setTotalOccurrences(9999);
  paymentScheduleType.setTrialOccurrences(1);

  const opaqueDataType = new ApiContracts.OpaqueDataType();

  opaqueDataType.setDataDescriptor(opaqueDataDescriptor);
  opaqueDataType.setDataValue(opaqueDataValue);

  const paymentType = new ApiContracts.PaymentType();

  paymentType.setOpaqueData(opaqueDataType);

  const customer = new ApiContracts.CustomerType();

  customer.setType(ApiContracts.CustomerTypeEnum.BUSINESS);
  customer.setEmail('testUser@example.com');

  const nameAndAddressType = new ApiContracts.NameAndAddressType();

  nameAndAddressType.setFirstName('Test');
  nameAndAddressType.setLastName('User');

  const arbSubscriptionType = new ApiContracts.ARBSubscriptionType();

  arbSubscriptionType.setName('fullQuarterly');
  arbSubscriptionType.setPaymentSchedule(paymentScheduleType);
  arbSubscriptionType.setAmount(225);
  arbSubscriptionType.setTrialAmount(150);
  arbSubscriptionType.setPayment(paymentType);
  arbSubscriptionType.setCustomer(customer);
  arbSubscriptionType.setBillTo(nameAndAddressType);

  const createRequest = new ApiContracts.ARBCreateSubscriptionRequest();

  createRequest.setMerchantAuthentication(merchantAuthenticationType);
  createRequest.setSubscription(arbSubscriptionType);

  console.log(JSON.stringify(createRequest.getJSON(), null, 2));
  const ctrl = new ApiControllers.ARBCreateSubscriptionController(createRequest.getJSON());

  ctrl.execute(() =&amp;gt; {
    const apiResponse = ctrl.getResponse(),
          response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse);

    logger.info('[authorize.net] Create Subscription Response:\n', JSON.stringify(response));
  });
}&lt;/PRE&gt;&lt;P&gt;And the logs (first the request that is to be sent, which I then grabbed and tried in the API console. Second is the response I got in Node):&lt;/P&gt;&lt;PRE&gt;{
  "ARBCreateSubscriptionRequest": {
    "merchantAuthentication": {
      "name": "mySandboxName",
      "transactionKey": "mySandboxKey"
    },
    "clientId": null,
    "subscription": {
      "name": "fullQuarterly",
      "paymentSchedule": {
        "interval": {
          "length": 3,
          "unit": "months"
        },
        "startDate": "2019-11-26",
        "totalOccurrences": 9999,
        "trialOccurrences": 1
      },
      "amount": 225,
      "trialAmount": 150,
      "payment": {
        "opaqueData": {
          "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
          "dataValue": "eyJjb2RlIjoiNTBfMl8wNjAwMDUzQTk5NkZEMjNCQTUwQjIwMUZDQzRFNTU0ODJFM0U5QTNBQ0I4RDNCNTJCMkVGQUVEMjFDRTY3RDlBODg2QUMyRTlDM0EyNzE0Njk4QjFENjA2NDc2NDM0RUFGMDkyREE1IiwidG9rZW4iOiI5NTc0NzQyOTM0NDA3Njc1MDAzNjAyIiwidiI6IjEuMSJ9"
        }
      },
      "customer": {
        "type": "business",
        "email": "testUser@example.com"
      },
      "billTo": {
        "firstName": "Test",
        "lastName": "User"
      }
    }
  }
}
&lt;BR /&gt;
info: [authorize.net] Create Subscription Response:
 {"messages":{"resultCode":"Error","message":[{"code":"E00114","text":"Invalid OTS Token."}]}}&lt;/PRE&gt;&lt;P&gt;Live console response:&lt;/P&gt;&lt;PRE&gt;													
{
    "subscriptionId": "6165150",
    "profile": {
        "customerProfileId": "1921875673",
        "customerPaymentProfileId": "1834822332"
    },
    "messages": {
        "resultCode": "Ok",
        "message": [
            {
                "code": "I00001",
                "text": "Successful."
            }
        ]
    }
}&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Nov 2019 04:54:10 GMT</pubDate>
    <dc:creator>Chee7ah</dc:creator>
    <dc:date>2019-11-26T04:54:10Z</dc:date>
    <item>
      <title>E00114 - "Invalid OTS Token." in Node, but works through the API Live Console</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/69820#M42773</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenario: &lt;/STRONG&gt;Using Accept.js to get opaque data which is then used on a Node server to create a subscription.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem: &lt;/STRONG&gt;Everytime I get an&amp;nbsp;"Invalid OTS Token." response, but if I try the exact same JSON request at&amp;nbsp;&lt;A href="https://developer.authorize.net/api/reference/index.html#recurring-billing-create-a-subscription" target="_blank"&gt;https://developer.authorize.net/api/reference/index.html#recurring-billing-create-a-subscription&lt;/A&gt;, then it succeeds.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt; What could be the problem? I assume it's not the payload, nor that it's sent multiple times as it works the second time in the API live console. But what else could it be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;PRE&gt;function createSubscription(req, res) {
  const { opaqueDataDescriptor, opaqueDataValue } = req.body;

  const merchantAuthenticationType = new ApiContracts.MerchantAuthenticationType();

  merchantAuthenticationType.setName(config.authorizeNet.loginId);
  merchantAuthenticationType.setTransactionKey(config.authorizeNet.transactionKey);

  const interval = new ApiContracts.PaymentScheduleType.Interval();

  interval.setLength(3);
  interval.setUnit(ApiContracts.ARBSubscriptionUnitEnum.MONTHS);

  const paymentScheduleType = new ApiContracts.PaymentScheduleType();

  paymentScheduleType.setInterval(interval);
  paymentScheduleType.setStartDate((new Date()).toISOString().substring(0, 10));
  paymentScheduleType.setTotalOccurrences(9999);
  paymentScheduleType.setTrialOccurrences(1);

  const opaqueDataType = new ApiContracts.OpaqueDataType();

  opaqueDataType.setDataDescriptor(opaqueDataDescriptor);
  opaqueDataType.setDataValue(opaqueDataValue);

  const paymentType = new ApiContracts.PaymentType();

  paymentType.setOpaqueData(opaqueDataType);

  const customer = new ApiContracts.CustomerType();

  customer.setType(ApiContracts.CustomerTypeEnum.BUSINESS);
  customer.setEmail('testUser@example.com');

  const nameAndAddressType = new ApiContracts.NameAndAddressType();

  nameAndAddressType.setFirstName('Test');
  nameAndAddressType.setLastName('User');

  const arbSubscriptionType = new ApiContracts.ARBSubscriptionType();

  arbSubscriptionType.setName('fullQuarterly');
  arbSubscriptionType.setPaymentSchedule(paymentScheduleType);
  arbSubscriptionType.setAmount(225);
  arbSubscriptionType.setTrialAmount(150);
  arbSubscriptionType.setPayment(paymentType);
  arbSubscriptionType.setCustomer(customer);
  arbSubscriptionType.setBillTo(nameAndAddressType);

  const createRequest = new ApiContracts.ARBCreateSubscriptionRequest();

  createRequest.setMerchantAuthentication(merchantAuthenticationType);
  createRequest.setSubscription(arbSubscriptionType);

  console.log(JSON.stringify(createRequest.getJSON(), null, 2));
  const ctrl = new ApiControllers.ARBCreateSubscriptionController(createRequest.getJSON());

  ctrl.execute(() =&amp;gt; {
    const apiResponse = ctrl.getResponse(),
          response = new ApiContracts.ARBCreateSubscriptionResponse(apiResponse);

    logger.info('[authorize.net] Create Subscription Response:\n', JSON.stringify(response));
  });
}&lt;/PRE&gt;&lt;P&gt;And the logs (first the request that is to be sent, which I then grabbed and tried in the API console. Second is the response I got in Node):&lt;/P&gt;&lt;PRE&gt;{
  "ARBCreateSubscriptionRequest": {
    "merchantAuthentication": {
      "name": "mySandboxName",
      "transactionKey": "mySandboxKey"
    },
    "clientId": null,
    "subscription": {
      "name": "fullQuarterly",
      "paymentSchedule": {
        "interval": {
          "length": 3,
          "unit": "months"
        },
        "startDate": "2019-11-26",
        "totalOccurrences": 9999,
        "trialOccurrences": 1
      },
      "amount": 225,
      "trialAmount": 150,
      "payment": {
        "opaqueData": {
          "dataDescriptor": "COMMON.ACCEPT.INAPP.PAYMENT",
          "dataValue": "eyJjb2RlIjoiNTBfMl8wNjAwMDUzQTk5NkZEMjNCQTUwQjIwMUZDQzRFNTU0ODJFM0U5QTNBQ0I4RDNCNTJCMkVGQUVEMjFDRTY3RDlBODg2QUMyRTlDM0EyNzE0Njk4QjFENjA2NDc2NDM0RUFGMDkyREE1IiwidG9rZW4iOiI5NTc0NzQyOTM0NDA3Njc1MDAzNjAyIiwidiI6IjEuMSJ9"
        }
      },
      "customer": {
        "type": "business",
        "email": "testUser@example.com"
      },
      "billTo": {
        "firstName": "Test",
        "lastName": "User"
      }
    }
  }
}
&lt;BR /&gt;
info: [authorize.net] Create Subscription Response:
 {"messages":{"resultCode":"Error","message":[{"code":"E00114","text":"Invalid OTS Token."}]}}&lt;/PRE&gt;&lt;P&gt;Live console response:&lt;/P&gt;&lt;PRE&gt;													
{
    "subscriptionId": "6165150",
    "profile": {
        "customerProfileId": "1921875673",
        "customerPaymentProfileId": "1834822332"
    },
    "messages": {
        "resultCode": "Ok",
        "message": [
            {
                "code": "I00001",
                "text": "Successful."
            }
        ]
    }
}&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 04:54:10 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/69820#M42773</guid>
      <dc:creator>Chee7ah</dc:creator>
      <dc:date>2019-11-26T04:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: E00114 - "Invalid OTS Token." in Node, but works through the API Live Console</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/70017#M42921</link>
      <description>&lt;P&gt;Still have no idea what's wrong here, but a different approach worked.&lt;/P&gt;&lt;P&gt;1. Created a customer profile with a customer paypment profile first with the opaque data&lt;/P&gt;&lt;P&gt;2. Created a subscription with the new customer profile and customer payment profile ids.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One catch I ran into: Apparently it takes like 10 seconds for the payment profile to be available for subscriptions. After creation I could immediately make a request to validate it and it succeeds. But creating a subscription fails with E00040 -&amp;nbsp;&lt;SPAN&gt;The record cannot be found. As a workaround added some retry logic to keep trying and after about 10 sec it succeeds...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 04:39:24 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/70017#M42921</guid>
      <dc:creator>Chee7ah</dc:creator>
      <dc:date>2019-12-14T04:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: E00114 - "Invalid OTS Token." in Node, but works through the API Live Console</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/70210#M43072</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A id="link_1" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://community.developer.authorize.net/t5/user/viewprofilepage/user-id/34264" target="_self"&gt;Chee7ah&lt;/A&gt;,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;Creating a subscription automatically creates a Customer Profile. Unless there is a particular reason that you want to do both separately, my recommendation would be to simply create the subscription and log the profile created when it is returned in the&amp;nbsp;&lt;SPAN&gt;ARBCreateSubscriptionResponse.&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN&gt;Elaine&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 21:33:12 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/E00114-quot-Invalid-OTS-Token-quot-in-Node-but-works-through-the/m-p/70210#M43072</guid>
      <dc:creator>ElaineM</dc:creator>
      <dc:date>2020-01-02T21:33:12Z</dc:date>
    </item>
  </channel>
</rss>

