Jump to content


Photo

Adaptivepayments Issue From Curl


  • Please log in to reply
No replies to this topic

#1 Alevsk

Alevsk

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 07 August 2015 - 07:22 AM

Hi, Im creating a simple web application in php that consume the adaptivePayments/Pay Api of paypal, I made some test using POSTMAN and everything works fine, I make the initial request and I get my payKey, also with this payKey I can check the status of the transaction using the /AdaptivePayments/PaymentDetails Api, the problem is when I try to make the request via php code:

        $endpoint = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
        
        $payload['actionType']                       = "PAY";
        $payload['clientDetails']['applicationId']   = "APP-80W284485P519543T";
        $payload['clientDetails']['ipAddress']       = "xxx.xxx.xxx.xxx";
        $payload['currencyCode']                     = "USD";
        $payload['feesPayer']                        = "EACHRECEIVER";
        $payload['memo']                             = "Transaction";
        $payload['receiverList']['receiver']         = $receivers;
        $payload['requestEnvelope']['errorLanguage'] = "en_US";
        $payload['returnUrl']                        = "URL";
        $payload['cancelUrl']                        = "URL";
        
        $json = json_encode($payload);
        
        $ch = curl_init($endpoint);


        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'X-PAYPAL-SECURITY-USERID: ACCOUNT',
            'X-PAYPAL-SECURITY-PASSWORD: PASSWORD',
            'X-PAYPAL-SECURITY-SIGNATURE: SIGNATURE',
            'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
            'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
            'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T',
            'Content-Type: application/json',
            'Content-Length: ' . strlen($json)
        ));
        
        $result = curl_exec($ch);

$receivers is a PHP array that contain information about emails and payment amounts, something like this:

 

Array
(
    [0] => Array
        (
            [amount] => 19.8
            [email] => client2-ubs@gmail.com
            [primary] => 
        )


    [1] => Array
        (
            [amount] => 20.7
            [email] => client1-ubs@gmail.com
            [primary] => 
        )


    [2] => Array
        (
            [amount] => 45
            [email] => store-ubs@gmail.com
            [primary] => 1
        )


)

I dont get any error, I even get the payKey which I use to create the html button so the user can pay for his goods, the problem is when I check the payment status /AdaptivePayments/PaymentDetails, Im getting:

 

{
    "responseEnvelope": {
        "timestamp": "2015-08-06T23:59:23.075-07:00",
        "ack": "Success",
        "correlationId": "bab22ca0bd887",
        "build": "17603431"
    },
    "cancelUrl": "https://23410a33.ngrok.com/universal-bank-of-souls/",
    "currencyCode": "USD",
    "paymentInfoList": null,
    "returnUrl": "https://23410a33.ngrok.com/universal-bank-of-souls/",
    "status": "CREATED",
    "payKey": "AP-8ML17897XK803351A",
    "actionType": "PAY",
    "feesPayer": "EACHRECEIVER",
    "sender": {
        "useCredentials": "false"
    }
}

for some strange reason paymentInfoList is null, so the user see an error (transaction error) at the moment of click the paypal button.

 

As I said before, If i made the transaction using POSTMAN and then check the status I get a correct response:

 

{
    "responseEnvelope": {
        "timestamp": "2015-08-07T00:14:08.510-07:00",
        "ack": "Success",
        "correlationId": "b9049ba0d4cf1",
        "build": "17603431"
    },
    "cancelUrl": "URL",
    "currencyCode": "USD",
    "memo": "Bank of souls payment",
    "paymentInfoList": {
        "paymentInfo": [
            {
                "receiver": {
                    "amount": "123.30",
                    "email": "client2-ubs@gmail.com",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "SLKM4ZQ5FMSHG"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "510.30",
                    "email": "client1-ubs@gmail.com",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "8PUDR7LSRS4MJ"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "704.00",
                    "email": "store-ubs@gmail.com",
                    "primary": "true",
                    "paymentType": "SERVICE",
                    "accountId": "E29BAQX7C7P3N"
                },
                "pendingRefund": "false"
            }
        ]
    },
    "returnUrl": "URL",
    "status": "CREATED",
    "payKey": "AP-9MU4806743660523S",
    "actionType": "PAY",
    "feesPayer": "EACHRECEIVER",
    "reverseAllParallelPaymentsOnError": "false",
    "sender": {
        "useCredentials": "false"
    }
}

(paymentInfoList actually contains a json object with the goods, but this is doing the request manually using POSTMAN)

 

Could this be a PHP issue? some ideas to debug the curl connection will help me a lot.

 

PD: I have been debuging this the whole day, I even print_r the $json variable (i get the json format) and copy / paste directly in postman and its works, but for some reason the same using curl is not sending the $receivers information.

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users