2

I was trying this (Method) for Paypal adaptive payments first part goes well but after completing second part nothing happening and no error to view. I know this is already posted but I view all other answers but all in vain. I tried to look other option to do this functionality but it mostly available on "Ruby" or other frameworks but I need it in PHP

Here is the PHP code

class PaypalTest{
public $app_id = "APP-80W284485P519543T";
public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
public $paypalUrl="https://www.paypal.com/webscr?cmd=_ap-payment&paykey=";
public $headers;

function __construct(){
    $this->headers = array(
        "X-PAYPAL-SECURITY-USERID: ".$this->api_user,
        "X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
        "X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
        "X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
        "X-PAYPAL-APPLICATION-ID: ".$this->app_id,
    );

    $this->envelope = array(
        "errorLanguage" => "en_US",
        "detailLevel" => "ReturnAll"
    );
}

function getPaymentOptions($paykey){
    $packet = array(
        "requestEnvelope" => $this->envelope,
        "paykey" => $paykey
    );

    return $this->_paypalSend($packet,"getPaymentOptions");
}
function setPaymentOptions(){

}
function _paypalSend($data,$call){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
    $response = json_decode(curl_exec($ch),true);
    return $response;

}
function splitPay(){

// create the pay request
    $createPacket = array(
        "actionType" =>"PAY",
        "currencyCode" => "USD",
        "receiverList" => array(
            "receiver" => array(
                array(
                    "amount"=> "200.00",
                    "email"=>"sb-3oe0y636987@personal.example.com"
                )
            )
        ),
        "returnUrl" => "http://test.local/payments/confirm",
        "cancelUrl" => "http://test.local/payments/cancel",
        "requestEnvelope" => $this->envelope
    );

    $response = $this->_paypalSend($createPacket,"Pay");
    print_r($response);
    $payKey = $response['payKey'];
    $detailPacket = array(
        "requestEnvelope" => $this->envelope,
        "payKey" => $payKey,
        "receiverOptions" => array(
            array(
                "receiver" => array("email"=>"sb-3oe0y636987@personal.example.com"),
                "invoiceData" => array(
                    "item" => array(
                        array(
                            "name" => "Product 1",
                            "price" => "100.00",
                            "identifier" => "p1"
                        ),
                        array(
                            "name" => "Product 2",
                            "price" => "100.00",
                            "identifier" => "p1"
                        )
                    )
                )
            )
        )
    );

    $response = $this->_paypalSend($detailPacket,"setPaymentOptions");
    echo $response;
    print_r($response);
    $dets = $this->getPaymentOptions($payKey);
    print_r($dets);
}
}

$payment = new PaypalTest();
$payment->splitPay();
Preston PHX
  • 27,642
  • 4
  • 24
  • 44
Mr Perfect
  • 116
  • 8
  • Do you have a live App ID for adaptive payments? The issue may be moot since Adaptive Payments is very old and no longer supported for new integrations. You will not be able to do anything with this even if you do get it working in sandbox. – Preston PHX Feb 29 '20 at 18:13
  • Is there any other solution which work like this? – Mr Perfect Feb 29 '20 at 18:21

1 Answers1

1

Adaptive Payments is no longer supported for new integrations and should not be used.

Instead, switch to a supported integration such as PayPal Checkout.

(There is also the more specialized PayPal Commerce Platform, available only to approved PayPal Partners.)

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • But it returning "payKey" what mean for that? – Mr Perfect Feb 29 '20 at 18:20
  • For split payments to multiple receivers? EC Parallel Payments does not require a live APP ID and so might be usable at the moment, but is also deprecated and may not be supported in the future. https://developer.paypal.com/docs/archive/express-checkout/integration-guide/ECParallelPayments/ – Preston PHX Feb 29 '20 at 18:27