0

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] => [email protected]
            [primary] => 
        )


    [1] => Array
        (
            [amount] => 20.7
            [email] => [email protected]
            [primary] => 
        )


    [2] => Array
        (
            [amount] => 45
            [email] => [email protected]
            [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": "[email protected]",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "SLKM4ZQ5FMSHG"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "510.30",
                    "email": "[email protected]",
                    "primary": "false",
                    "paymentType": "SERVICE",
                    "accountId": "8PUDR7LSRS4MJ"
                },
                "pendingRefund": "false"
            },
            {
                "receiver": {
                    "amount": "704.00",
                    "email": "[email protected]",
                    "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 request using curl is not sending the $receivers information.

1
  • It looks like the transaction simply isn't completed. That's why it's still showing CREATED. After you get the PayKey you have to redirect the user to PayPal so they can login and complete the payment (unless you're using a preapproval key, but I don't see that you are.) Are you doing the redirect and actually completing the payment? Aug 8, 2015 at 2:00

1 Answer 1

0

Solved, I was making the requests (create the order and the request order information) using two different api credentials, also, it seems that paypal hide the order goods when receiving api credentials different than the originals, however still showing the state of the order (CREATE, COMPLETED, etc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.