<?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 Re: Issue with creating transaction and subscription in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64697#M38522</link>
    <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;SPAN&gt;Richard. That solved my issue. I also had to add a delay before serving the subscription&amp;nbsp;Curl.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Oct 2018 13:41:16 GMT</pubDate>
    <dc:creator>the94air</dc:creator>
    <dc:date>2018-10-07T13:41:16Z</dc:date>
    <item>
      <title>Issue with creating transaction and subscription</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64663#M38492</link>
      <description>&lt;P&gt;I am trying to create a transaction using accept js and on the backend, I have 2 curl requests. One for the transaction request and the other for the subscription request. I have a checkbox on the payment for asking if the users want to make his payment a recurring payment. The transaction request is working just fine but the subscription request is failing. I tried to comment out the transaction code and only run the recurring request but it still showing this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;messages: {
    resultCode: "Error",
    message: {
        code: "E00114",
        text: "Invalid OTS Token."
    }
}&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Here is all my PHP logic on the controller&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&amp;lt;?php
    $loginId = AUTHROIZE_NET_LOGIN_ID;
    $transactionKey = AUTHROIZE_NET_TRANSACTION_KEY;

    // Posted data:
    // $request-&amp;gt;amount = $_POST['amount'];
    // $request-&amp;gt;first_name = $_POST['first_name'];
    // $request-&amp;gt;last_name = $_POST['last_name'];
    // $request-&amp;gt;dataDesc = $_POST['dataDesc'];
    // $request-&amp;gt;dataValue = $_POST['dataValue'];

    $transRequestXmlStr = &amp;lt;&amp;lt;&amp;lt;XML
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;createTransactionRequest&amp;gt;
    &amp;lt;merchantAuthentication&amp;gt;&amp;lt;/merchantAuthentication&amp;gt;
    &amp;lt;transactionRequest&amp;gt;
        &amp;lt;transactionType&amp;gt;authCaptureTransaction&amp;lt;/transactionType&amp;gt;
        &amp;lt;amount&amp;gt;assignAMOUNT&amp;lt;/amount&amp;gt;
        &amp;lt;currencyCode&amp;gt;USD&amp;lt;/currencyCode&amp;gt;
        &amp;lt;payment&amp;gt;
            &amp;lt;opaqueData&amp;gt;
                &amp;lt;dataDescriptor&amp;gt;assignDD&amp;lt;/dataDescriptor&amp;gt;
                &amp;lt;dataValue&amp;gt;assignDV&amp;lt;/dataValue&amp;gt;
            &amp;lt;/opaqueData&amp;gt;
        &amp;lt;/payment&amp;gt;
        &amp;lt;billTo&amp;gt;
            &amp;lt;firstName&amp;gt;firstN&amp;lt;/firstName&amp;gt;
            &amp;lt;lastName&amp;gt;lastN&amp;lt;/lastName&amp;gt;
        &amp;lt;/billTo&amp;gt;
    &amp;lt;/transactionRequest&amp;gt;
&amp;lt;/createTransactionRequest&amp;gt;
XML;

    $transRequestXml = new \SimpleXMLElement($transRequestXmlStr);

    $transRequestXml-&amp;gt;addAttribute('xmlns','AnetApi/xml/v1/schema/AnetApiSchema.xsd');

    $transRequestXml-&amp;gt;merchantAuthentication-&amp;gt;addChild('name',$loginId);
    $transRequestXml-&amp;gt;merchantAuthentication-&amp;gt;addChild('transactionKey',$transactionKey);

    $transRequestXml-&amp;gt;transactionRequest-&amp;gt;amount = $request-&amp;gt;amount;
    $transRequestXml-&amp;gt;transactionRequest-&amp;gt;billTo-&amp;gt;firstName = $request-&amp;gt;first_name;
    $transRequestXml-&amp;gt;transactionRequest-&amp;gt;billTo-&amp;gt;lastName = $request-&amp;gt;last_name;
    $transRequestXml-&amp;gt;transactionRequest-&amp;gt;payment-&amp;gt;opaqueData-&amp;gt;dataDescriptor = $request-&amp;gt;dataDesc;
    $transRequestXml-&amp;gt;transactionRequest-&amp;gt;payment-&amp;gt;opaqueData-&amp;gt;dataValue = $request-&amp;gt;dataValue;

    $url="https://api.authorize.net/xml/v1/request.api";

    try {
        //setting the curl parameters.
        $ch = curl_init();
        if (FALSE === $ch)
            throw new Exception('failed to initialize');
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $transRequestXml-&amp;gt;asXML());
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        //curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
        $content = curl_exec($ch);
        if (FALSE === $content)
            throw new Exception(curl_error($ch), curl_errno($ch));
        curl_close($ch);
        
        $content = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content);
        $xmlResult=simplexml_load_string($content);

        $jsonResult = json_encode($xmlResult);

        $objResult = json_decode($jsonResult);

        if($objResult-&amp;gt;transactionResponse-&amp;gt;responseCode == "1") {
            // Success
        }
          
        // echo $jsonResult;

    } catch(Exception $e) {
        trigger_error(sprintf('Curl failed with error #%d: %s', $e-&amp;gt;getCode(), $e-&amp;gt;getMessage()), E_USER_ERROR);
    }

    $transRequestXmlStr2 = &amp;lt;&amp;lt;&amp;lt;XML
&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;ARBCreateSubscriptionRequest&amp;gt;
    &amp;lt;merchantAuthentication&amp;gt;&amp;lt;/merchantAuthentication&amp;gt;
    &amp;lt;subscription&amp;gt;
        &amp;lt;name&amp;gt;Quick donation&amp;lt;/name&amp;gt;
        &amp;lt;paymentSchedule&amp;gt;
			&amp;lt;interval&amp;gt;
				&amp;lt;length&amp;gt;1&amp;lt;/length&amp;gt;
				&amp;lt;unit&amp;gt;months&amp;lt;/unit&amp;gt;
			&amp;lt;/interval&amp;gt;
			&amp;lt;startDate&amp;gt;2020-08-30&amp;lt;/startDate&amp;gt;
			&amp;lt;totalOccurrences&amp;gt;9999&amp;lt;/totalOccurrences&amp;gt;
		&amp;lt;/paymentSchedule&amp;gt;
        &amp;lt;amount&amp;gt;assignAMOUNT&amp;lt;/amount&amp;gt;
        &amp;lt;payment&amp;gt;
            &amp;lt;opaqueData&amp;gt;
                &amp;lt;dataDescriptor&amp;gt;assignDD&amp;lt;/dataDescriptor&amp;gt;
                &amp;lt;dataValue&amp;gt;assignDV&amp;lt;/dataValue&amp;gt;
            &amp;lt;/opaqueData&amp;gt;
        &amp;lt;/payment&amp;gt;
        &amp;lt;billTo&amp;gt;
            &amp;lt;firstName&amp;gt;firstN&amp;lt;/firstName&amp;gt;
            &amp;lt;lastName&amp;gt;lastN&amp;lt;/lastName&amp;gt;
        &amp;lt;/billTo&amp;gt;
    &amp;lt;/subscription&amp;gt;
&amp;lt;/ARBCreateSubscriptionRequest&amp;gt;
XML;
          
    $transRequestXml2 = new \SimpleXMLElement($transRequestXmlStr2);

    $transRequestXml2-&amp;gt;addAttribute('xmlns','AnetApi/xml/v1/schema/AnetApiSchema.xsd');

    $transRequestXml2-&amp;gt;merchantAuthentication-&amp;gt;addChild('name',$loginId);
    $transRequestXml2-&amp;gt;merchantAuthentication-&amp;gt;addChild('transactionKey',$transactionKey);
    
    $transRequestXml2-&amp;gt;subscription-&amp;gt;paymentSchedule-&amp;gt;startDate = date('Y-m-d');
    $transRequestXml2-&amp;gt;subscription-&amp;gt;amount = $request-&amp;gt;amount;
    $transRequestXml2-&amp;gt;subscription-&amp;gt;billTo-&amp;gt;firstName = $request-&amp;gt;first_name;
    $transRequestXml2-&amp;gt;subscription-&amp;gt;billTo-&amp;gt;lastName = $request-&amp;gt;last_name;
    $transRequestXml2-&amp;gt;subscription-&amp;gt;payment-&amp;gt;opaqueData-&amp;gt;dataDescriptor = $request-&amp;gt;dataDesc;
    $transRequestXml2-&amp;gt;subscription-&amp;gt;payment-&amp;gt;opaqueData-&amp;gt;dataValue = $request-&amp;gt;dataValue;
            
    $url2 = "https://api.authorize.net/xml/v1/request.api";

    try {
        //setting the curl parameters.
        $ch2 = curl_init();
        if (FALSE === $ch2)
            throw new Exception('failed to initialize');
        curl_setopt($ch2, CURLOPT_URL, $url2);
        curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
        curl_setopt($ch2, CURLOPT_POSTFIELDS, $transRequestXml2-&amp;gt;asXML());
        curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch2, CURLOPT_CONNECTTIMEOUT, 300);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
        // curl_setopt($ch2, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
        $content2 = curl_exec($ch2);
        if (FALSE === $content2)
            throw new Exception(curl_error($ch2), curl_errno($ch2));
        curl_close($ch2);

        $content2 = str_replace(' xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd"', '', $content2);
        $xmlResult2 = simplexml_load_string($content2);

        $jsonResult2 = json_encode($xmlResult2);

        $objResult2 = json_decode($jsonResult2);

        // echo $jsonResult2;

    } catch(Exception $e) {
        trigger_error(sprintf('Curl failed with error #%d: %s', $e-&amp;gt;getCode(), $e-&amp;gt;getMessage()), E_USER_ERROR);
    }&lt;/PRE&gt;&lt;P&gt;I am very confused. I&amp;nbsp;couldn't find any solution online for&amp;nbsp;the issue. This that the right way to create the requests? Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 14:48:25 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64663#M38492</guid>
      <dc:creator>the94air</dc:creator>
      <dc:date>2018-10-03T14:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with creating transaction and subscription</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64670#M38498</link>
      <description>&lt;P&gt;Can you at least tell me what the "Invalid OTS Token." error means. This will be super helpful. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 06:27:03 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64670#M38498</guid>
      <dc:creator>the94air</dc:creator>
      <dc:date>2018-10-04T06:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with creating transaction and subscription</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64675#M38503</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.developer.cybersource.com/t5/user/viewprofilepage/user-id/26490"&gt;@the94air&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The payment nonce returned by Accept.js can only be used once, which is why you are receiving the E000114 error when attempting to create a subscription using the nonce a second time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When creating your initial transaction, set the option to create a customer profile.&amp;nbsp; Then if the transaction is successful, the response will include a customer profile id (token) which can be used to create a subscription.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Richard&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 13:00:44 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64675#M38503</guid>
      <dc:creator>RichardH</dc:creator>
      <dc:date>2018-10-04T13:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with creating transaction and subscription</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64697#M38522</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;SPAN&gt;Richard. That solved my issue. I also had to add a delay before serving the subscription&amp;nbsp;Curl.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 13:41:16 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Issue-with-creating-transaction-and-subscription/m-p/64697#M38522</guid>
      <dc:creator>the94air</dc:creator>
      <dc:date>2018-10-07T13:41:16Z</dc:date>
    </item>
  </channel>
</rss>

