0

我在一个 CakePHP 项目中工作,我需要使用 Paypal 的自适应支付/并行支付功能。在这种情况下,我的客户的付款将分成 2 份,一份给另一个客户,另一份给我,即管理员。

我正在尝试,但总是收到“4002 错误”消息。提示现在无法处理付款,请稍后再试。

这是我的控制器代码:

<?php
    App::uses('AppController','Controller');

    Class PaymentsController extends AppController{

    public $name='Payments';
    public $helpers=array('Text');
    public $components=array();

    public $uses=array('Payment');

    var $paypalUrl="https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";//send  the user here after all is setup
    .
    .
    .
    public function pay(){
       $amount1=10.50;
       $email1="client@email.com";
       $amount2=15.80;
       $email2="admin@email.com";
       $finalUrl="http://example.com/successful";
       $cancelUrl="http://example.com/failed";
       $payKey=$this->Paypal->splitPay($amount1,$email1,$amount2,$email2,$cancelUrl,$finalUrl);
       $this->redirect($this->paypalUrl.$payKey);
    }
    .
    .
    .
}

我将访问贝宝的代码放在“付款”模型中。就这个 :

<?php
    App::uses('AuthComponent','Controller/Component');
    class Paypal extends AppModel{
      function __construct(){
           $this->headers=array(
              "X-PAYPAL-SECURITY-USERID: ".PAYPAL_ID,
              "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: ".APPLICANT_ID
           );
           $this->envelope=array(
              "errorLanguage"=>"en-US",
              "detailLevel"=>"ReturnAll"
           );
      }

      //wrapper for getting payment details
      function getPaymentOptions($paykey){
          $packet=array(
             "requestEnvelope"=>$this->envelope,
             "payKey"=>$paykey
          );

          return $this->_paypalSend($packet,"GetPaymentOptions");
      }

      //set payment details
      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);

          return json_decode(curl_exec($ch),TRUE);
      }

      //this is where we do work
      function splitPay($amount1,$email1,$amount2,$email2,$cancelUrl,$finalUrl){
          //create the pay request
          $createPacket=array(
             "actionType"=>"PAY",
             "currencyCode"=>"USD",
             "receiverList"=>array(
                 "receiver"=>array(
                     array(
                        "amount"=>$amount1,
                        "email"=>$email1
                     ),
                     array(
                        "amount"=>$amount2,
                        "email"=>$email2
                     ),
                 )
             ),
             "returnUrl"=>$finalUrl,
             "cancelUrl"=>$cancelUrl,
             "requestEnvelope"=>$this->envelope
          );
          $response=$this->_paypalSend($createPacket,"Pay");
          $payKey=$response['payKey'];

          return $payKey;
      }

我不明白这里有什么问题。

4

0 回答 0