Search code examples
paypalrecurring-billing

PayPal CreateRecurringPaymentsProfile Invalid token


I'm trying to create recurring payment using SOAP API , i did the following steps as mentioned in PayPal API manual :

1- Call "set express checkout" API. 2- Get token and redirect the buyer to PayPal site. 3- After user finished he will redirected to my response page. 4- Call "do express checkout" API. 5- Call "CreateRecurringPaymentsProfile" API.

my call SOAP structure:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ebay:api:PayPalAPI" xmlns:urn1="urn:ebay:apis:eBLBaseComponents">
  <soapenv:Header>
    <urn:RequesterCredentials>
      <urn1:Credentials>
        <urn1:Username>'+un+'</urn1:Username>
        <urn1:Password>'+pw+'</urn1:Password>
        <urn1:Signature>'+sig+'</urn1:Signature>
      </urn1:Credentials>
    </urn:RequesterCredentials>
  </soapenv:Header>
  <soapenv:Body>
    <urn:CreateRecurringPaymentsProfileReq>
      <urn:CreateRecurringPaymentsProfileRequest>
        <urn1:Version>'+version+'</urn1:Version>
        <urn1:CreateRecurringPaymentsProfileRequestDetails>
          <urn1:Token>'+token+'</urn1:Token>
          <urn1:RecurringPaymentsProfileDetails>
            <urn1:SubscriberName>'+FirstName+' '+LastName+'</urn1:SubscriberName>
            <urn1:BillingStartDate>'+strCurrentDate+'</urn1:BillingStartDate>
          </urn1:RecurringPaymentsProfileDetails>
          <urn1:ScheduleDetails>
            <urn1:Description>'+BillingAgreementDescription+'</urn1:Description>
            <urn1:PaymentPeriod>
              <urn1:BillingPeriod>'+billingPeriod+'</urn1:BillingPeriod>
              <urn1:BillingFrequency>'+billingFrequency+'</urn1:BillingFrequency>
              <urn1:Amount currencyID="'+UsedCurrency+'">'+amount+'</urn1:Amount>
            </urn1:PaymentPeriod>
          </urn1:ScheduleDetails>
        </urn1:CreateRecurringPaymentsProfileRequestDetails>
      </urn:CreateRecurringPaymentsProfileRequest>
    </urn:CreateRecurringPaymentsProfileReq>
  </soapenv:Body>
</soapenv:Envelope>


Solution

  • It's problem with SOAP body structure it should be like :

      string doExpressCheckout = '';
        doExpressCheckout += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ebay:api:PayPalAPI" xmlns:urn1="urn:ebay:apis:eBLBaseComponents">';
        doExpressCheckout += '<soapenv:Header>';
        doExpressCheckout += '<urn:RequesterCredentials>';
        doExpressCheckout += '<urn1:Credentials>';
        doExpressCheckout += '<urn1:Username>'+un+'</urn1:Username>';
        doExpressCheckout += '<urn1:Password>'+pw+'</urn1:Password>';
        doExpressCheckout += '<urn1:Signature>'+sig+'</urn1:Signature>';
        doExpressCheckout += '</urn1:Credentials>';
        doExpressCheckout += '</urn:RequesterCredentials>';
        doExpressCheckout += '</soapenv:Header>';
        doExpressCheckout += '<soapenv:Body>';
        doExpressCheckout += '<urn:DoExpressCheckoutPaymentReq>';
        doExpressCheckout += '<urn:DoExpressCheckoutPaymentRequest>';
        doExpressCheckout += '<urn1:Version>'+version+'</urn1:Version>';
        doExpressCheckout += '<urn1:DoExpressCheckoutPaymentRequestDetails>';
        doExpressCheckout += '<urn1:Token>'+token+'</urn1:Token>';
        doExpressCheckout += '<urn1:PayerID>'+payerID+'</urn1:PayerID>';
        doExpressCheckout += '<urn1:PaymentDetails>';
        doExpressCheckout += '<urn1:OrderTotal currencyID="'+UsedCurrency+'">'+amount+'</urn1:OrderTotal>';
        doExpressCheckout += '</urn1:PaymentDetails>';
        doExpressCheckout += '</urn1:DoExpressCheckoutPaymentRequestDetails>';
        doExpressCheckout += '</urn:DoExpressCheckoutPaymentRequest>';
        doExpressCheckout += '</urn:DoExpressCheckoutPaymentReq>';
        doExpressCheckout += '</soapenv:Body>';
        doExpressCheckout += '</soapenv:Envelope>';