Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. <?php
  2. class PaypalTest {
  3.  
  4. public $api_user = "developer_api1.gmail.com";
  5. public $api_pass = "xxxxxxxxxxxxx";
  6. public $api_sig = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  7. public $app_id = "APP-80W284485P519543T";
  8. public $apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/';
  9. public $headers;
  10. public $paykey;
  11. public function __construct(){
  12.  
  13. $this->headers = array(
  14. "X-PAYPAL-SECURITY-USERID: ".$this->api_user,
  15. "X-PAYPAL-SECURITY-PASSWORD: ".$this->api_pass,
  16. "X-PAYPAL-SECURITY-SIGNATURE: ".$this->api_sig,
  17. "X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
  18. "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
  19. "X-PAYPAL-APPLICATION-ID: ".$this->app_id,
  20. );
  21. }
  22.  
  23. public function getPaymentOptions($paykey){
  24. $createPacket = array(
  25. "actionType" =>"PAY",
  26. "payKey" =>$paykey,
  27. "currencyCode" => "USD",
  28. "senderEmail" => 'example-buyer@gmail.com',
  29. "receiverList" => array(
  30. "receiver" => array(
  31. array(
  32. "amount"=> "100.00",
  33. "email"=>"example-seller@gmail.com"
  34. ),
  35. array(
  36. "amount"=> "200.00",
  37. "email"=>"example-seller2@gmail.com"
  38. ),
  39. ),
  40. ),
  41. "returnUrl" => "http://127.0.0.1/paypal_adaptive/success.php",
  42. "cancelUrl" => "http://127.0.0.1/paypal_adaptive/cancel.php",
  43. "requestEnvelope" => array(
  44. "errorLanguage" => "en_US",
  45. "detailLevel" => "ReturnAll",
  46. ),
  47. );
  48. return $response = $this->_paypalSend($createPacket,"PaymentDetails");
  49. }
  50. public function _paypalSend($data,$call){
  51.  
  52. $ch = curl_init();
  53. curl_setopt($ch, CURLOPT_URL, $this->apiUrl.$call);
  54. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  55. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  56. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  57. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  58. curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
  59. $response = json_decode(curl_exec($ch),true);
  60. return $response;
  61.  
  62. }
  63. public function splitPay(){
  64.  
  65. // create the pay request
  66. $createPacket = array(
  67. "actionType" =>"PAY",
  68. "currencyCode" => "USD",
  69. "senderEmail" => 'example-buyer@gmail.com',
  70. "receiverList" => array(
  71. "receiver" => array(
  72. array(
  73. "amount"=> "100.00",
  74. "email"=>"example-seller@gmail.com"
  75. ),
  76. array(
  77. "amount"=> "200.00",
  78. "email"=>"example-seller2@gmail.com"
  79. ),
  80. ),
  81. ),
  82. "returnUrl" => "http://127.0.0.1/paypal_adaptive/success.php",
  83. "cancelUrl" => "http://127.0.0.1/paypal_adaptive/cancel.php",
  84. "requestEnvelope" => array(
  85. "errorLanguage" => "en_US",
  86. "detailLevel" => "ReturnAll",
  87. ),
  88. );
  89.  
  90. return $response = $this->_paypalSend($createPacket,"Pay");
  91.  
  92. }
  93. }
  94. $payment = new PaypalTest();
  95. $response = $payment->splitPay();
  96. $paykey = $response['payKey'];
  97. $response1 = $payment->getPaymentOptions($paykey);
  98. echo "<pre>";
  99. print_r($response1);
  100. ?>
  101.  
  102. Array
  103. (
  104. [responseEnvelope] => Array
  105. (
  106. [timestamp] => 2016-01-12T11:17:51.744-08:00
  107. [ack] => Success
  108. [correlationId] => 03dfdf2efd275
  109. [build] => 17820627
  110. )
  111.  
  112. [cancelUrl] => http://127.0.0.1/paypal_adaptive/cancel.php
  113. [currencyCode] => USD
  114. [paymentInfoList] => Array
  115. (
  116. [paymentInfo] => Array
  117. (
  118. [0] => Array
  119. (
  120. [receiver] => Array
  121. (
  122. [amount] => 100.00
  123. [email] => example-seller@gmail.com
  124. [primary] => false
  125. [paymentType] => SERVICE
  126. [accountId] => YQLSX8R2V5MHY
  127. )
  128.  
  129. [pendingRefund] => false
  130. )
  131.  
  132. [1] => Array
  133. (
  134. [receiver] => Array
  135. (
  136. [amount] => 200.00
  137. [email] => example-seller2@gmail.com
  138. [primary] => false
  139. [paymentType] => SERVICE
  140. [accountId] => WRSDL9ELY7MTU
  141. )
  142.  
  143. [pendingRefund] => false
  144. )
  145.  
  146. )
  147.  
  148. )
  149.  
  150. [returnUrl] => http://127.0.0.1/paypal_adaptive/success.php
  151. [senderEmail] => example-buyer@gmail.com
  152. [status] => CREATED
  153. [payKey] => AP-7DL251088A4194610
  154. [actionType] => PAY
  155. [feesPayer] => EACHRECEIVER
  156. [reverseAllParallelPaymentsOnError] => false
  157. [sender] => Array
  158. (
  159. [email] => example-buyer@gmail.com
  160. [accountId] => 5NWKWJZ8KG6Q2
  161. [useCredentials] => false
  162. )
  163.  
  164. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement