0
 public class using_simple_method
 {
     public void transeferr()
     {

        String url='https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
        string un='';
        string pw='';
        string sig ='';
         String doDirectRequest;

                  doDirectRequest += '<soap:Header><RequesterCredentials xmlns="urn:ebay:api:PayPalAPI"><Credentials xmlns="urn:ebay:apis:eBLBaseComponents">';
                  doDirectRequest += '<Username>' + un + '</Username><ebl:Password xmlns:ebl="urn:ebay:apis:eBLBaseComponents">' + pw;
                  doDirectRequest += '</ebl:Password><Signature>' + sig + '</Signature>';
                  doDirectRequest += '</Credentials></RequesterCredentials></soap:Header><soap:Body><PayRequest xmlns="http://svcs.sandbox.paypal.com/types/ap">';
                  doDirectRequest += '<actionType xmlns="">PAY</actionType>';
                  doDirectRequest += '<requestEnvelope xmlns=""><errorLanguage>en_US</errorLanguage></requestEnvelope>';
                  doDirectRequest += '<cancelUrl xmlns="">http://www.xchaos.co.uk</cancelUrl>';
                  doDirectRequest += '<currencyCode xmlns="">USD</currencyCode><feesPayer xmlns="">EACHRECEIVER</feesPayer>';
                  doDirectRequest += '<receiverList xmlns=""><receiver><amount>1</amount><email>[email protected]</email></receiver></receiverList>';
                  doDirectRequest += '<clientDetails><applicationId>APP-80W284485P519543T</applicationId></clientDetails>';
                  doDirectRequest += '<ipnNotificationUrl>http://www.xchaos.co.uk</ipnNotificationUrl>';       
                  doDirectRequest += '<returnUrl xmlns="">http://www.xchaos.co.uk</returnUrl>';
                  doDirectRequest += '</PayRequest>';
                  doDirectRequest += '</soap:Body></soap:Envelope>';

        Http h = new Http();
        HttpRequest req = new HttpRequest();          
        req.setBody(doDirectRequest);
        req.setEndpoint(url);         
        req.setMethod('POST');
        req.setHeader('Content-length', '1753' );
        req.setHeader('Content-Type', 'text/xml;charset=UTF-8');
        req.setHeader('SOAPAction','');
        req.setHeader('Host','api-aa.sandbox.paypal.com');
        system.debug('----------Request'+req);
        HttpResponse res =h.send(req);
        String xml = res.getBody();
        system.debug('----------'+res.getbody());         
    }
}

This produces an output as Authentication failed.

API credentials are incorrect. Error Code : 520003

4
  • Suggest you double check the un/pw/sig and that the account is correctly setup at the Paypal side. Also hard coding the Content-length makes no sense. Personally I would be using the REST/JSON API as it's easier to write code for in Apex.
    – Keith C
    Commented Mar 18, 2016 at 9:02
  • Hi Keith C, I have cross checked the un/pw/sig. Currently I am using developer paypal account credentials to integrate. I successfully done payment creation with the URL : "api-3t.sandbox.paypal.com/2.0" . But this adaptive payment uses "svcs.sandbox.paypal.com/AdaptivePayments/Pay" which is not even authenticating.If you have REST API sample code, Kindly send me .Thanks in advance Commented Mar 18, 2016 at 9:53
  • I don't have a REST example, but am suggesting if you are going to use a lot more of these APIs REST/JSON would be the way to go. You might need to pursue your authentication problem with Paypal.
    – Keith C
    Commented Mar 18, 2016 at 10:12
  • Hi Keith C, Thank You. I will use REST/JSON for integration Commented Mar 18, 2016 at 10:39

1 Answer 1

0
public class json_paypal {

    public void using_json() {

      String url='https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
      string un='';
      string pw='';
      string sig ='';

      HttpRequest req = new HttpRequest();

      req.setHeader('X-PAYPAL-SECURITY-USERID','');
      req.setHeader('X-PAYPAL-SECURITY-PASSWORD','');
      req.setHeader('X-PAYPAL-SECURITY-SIGNATURE','');
      req.setHeader('X-PAYPAL-APPLICATION-ID','APP-80W284485P519543T');
      req.setHeader('X-PAYPAL-REQUEST-DATA-FORMAT','JSON');
      req.setHeader('X-PAYPAL-RESPONSE-DATA-FORMAT','JSON');


      req.setHeader('content-type', 'application/json');
      req.setHeader('Accept', 'application/json');

      //JSONGenerator gen = JSON.createGenerator(true);
      //gen.writeStringField('def', 'xyz');

      String json = '{'+
        '  \"actionType\":\"PAY\",        '+
        '  \"currencyCode\":\"USD\",      '+
        '  \"receiverList\":{             '+
        '    \"receiver\":[{              '+
        '      \"amount\":\"1.00\",       '+
        '      \"email\":\"\"             '+
        '    }]                           '+
        '  },                             '+
        '  \"returnUrl\":,                '+
        '  \"cancelUrl\":,                '+
        '  \"senderEmail\":\"",           '+
        '  \"requestEnvelope\":{          '+
        '  \"errorLanguage\":\"en_US\",   '+
        '  \"detailLevel\":\"ReturnAll\"  '+
        '  }                              '+
        '}';

      //String pretty = gen.getAsString();
      String pretty = '';
      req.setBody(json);

      req.setEndpoint(url);         

      req.setMethod('POST');

      req.setHeader('SOAPAction','');
      req.setHeader('Host','api-aa.sandbox.paypal.com');

      system.debug('----------Request'+pretty);
      Http h = new Http();
      HttpResponse res =h.send(req);
      String xml = res.getBody();
      system.debug('----------'+res.getbody());         
  }
}
1
  • Using this code...Fill the necessary required fields and execute...U will make a request with Paypal Commented Mar 21, 2016 at 10:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .