Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PaypalTest {
- public $api_user = "developer_api1.gmail.com";
- public $api_pass = "xxxxxxxxxxxxx";
- public $api_sig = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- public $app_id = "APP-80W284485P519543T";
- public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
- public $headers;
- public $paykey;
- public 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,
- );
- }
- public function getPaymentOptions($paykey){
- $createPacket = array(
- "actionType" =>"PAY",
- "payKey" =>$paykey,
- "currencyCode" => "USD",
- "senderEmail" => 'example-buyer@gmail.com',
- "receiverList" => array(
- "receiver" => array(
- array(
- "amount"=> "100.00",
- "email"=>"example-seller@gmail.com"
- ),
- array(
- "amount"=> "200.00",
- "email"=>"example-seller2@gmail.com"
- ),
- ),
- ),
- "returnUrl" => "http://127.0.0.1/paypal_adaptive/success.php",
- "cancelUrl" => "http://127.0.0.1/paypal_adaptive/cancel.php",
- "requestEnvelope" => array(
- "errorLanguage" => "en_US",
- "detailLevel" => "ReturnAll",
- ),
- );
- return $response = $this->_paypalSend($createPacket,"PaymentDetails");
- }
- public 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;
- }
- public function splitPay(){
- // create the pay request
- $createPacket = array(
- "actionType" =>"PAY",
- "currencyCode" => "USD",
- "senderEmail" => 'example-buyer@gmail.com',
- "receiverList" => array(
- "receiver" => array(
- array(
- "amount"=> "100.00",
- "email"=>"example-seller@gmail.com"
- ),
- array(
- "amount"=> "200.00",
- "email"=>"example-seller2@gmail.com"
- ),
- ),
- ),
- "returnUrl" => "http://127.0.0.1/paypal_adaptive/success.php",
- "cancelUrl" => "http://127.0.0.1/paypal_adaptive/cancel.php",
- "requestEnvelope" => array(
- "errorLanguage" => "en_US",
- "detailLevel" => "ReturnAll",
- ),
- );
- return $response = $this->_paypalSend($createPacket,"Pay");
- }
- }
- $payment = new PaypalTest();
- $response = $payment->splitPay();
- $paykey = $response['payKey'];
- $response1 = $payment->getPaymentOptions($paykey);
- echo "<pre>";
- print_r($response1);
- ?>
- Array
- (
- [responseEnvelope] => Array
- (
- [timestamp] => 2016-01-12T11:17:51.744-08:00
- [ack] => Success
- [correlationId] => 03dfdf2efd275
- [build] => 17820627
- )
- [cancelUrl] => http://127.0.0.1/paypal_adaptive/cancel.php
- [currencyCode] => USD
- [paymentInfoList] => Array
- (
- [paymentInfo] => Array
- (
- [0] => Array
- (
- [receiver] => Array
- (
- [amount] => 100.00
- [email] => example-seller@gmail.com
- [primary] => false
- [paymentType] => SERVICE
- [accountId] => YQLSX8R2V5MHY
- )
- [pendingRefund] => false
- )
- [1] => Array
- (
- [receiver] => Array
- (
- [amount] => 200.00
- [email] => example-seller2@gmail.com
- [primary] => false
- [paymentType] => SERVICE
- [accountId] => WRSDL9ELY7MTU
- )
- [pendingRefund] => false
- )
- )
- )
- [returnUrl] => http://127.0.0.1/paypal_adaptive/success.php
- [senderEmail] => example-buyer@gmail.com
- [status] => CREATED
- [payKey] => AP-7DL251088A4194610
- [actionType] => PAY
- [feesPayer] => EACHRECEIVER
- [reverseAllParallelPaymentsOnError] => false
- [sender] => Array
- (
- [email] => example-buyer@gmail.com
- [accountId] => 5NWKWJZ8KG6Q2
- [useCredentials] => false
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement