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();
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.)