0

我正在使用贝宝自适应支付 api。它对我有用,我得到的唯一问题是 invoiceData 没有显示在贝宝上。所以任何帮助将不胜感激。

class client extends CI_Controller {

function __construct()
{
    parent::__construct();

    $this->headers = array(
        "X-PAYPAL-SECURITY-USERID: XXXXXXX",
        "X-PAYPAL-SECURITY-PASSWORD: XXXXXXX",
        "X-PAYPAL-SECURITY-SIGNATURE:XXXXXXX",
        "X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
        "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
        "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T"
    );

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

var $apiUrl = "https://svcs.sandbox.paypal.com/AdaptivePayments/";
var $paypalUrl = "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=";

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

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

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);
}

function splitPay()
{
    $createPacket = array(
        "actionType" => "PAY",
        "currencyCode" => "USD",
        "receiverList"  => array(
            "receiver"  =>  array(
                array(
                    "amount"    => "2.00",
                    "email"     => "test@gmail.com",
                    "invoiceId"     => "144781235842",
                ),
                array(
                    "amount"    => "2.00",
                    "email"     => "test2@gmail.com",
                    "invoiceId"     => "14478123582kbn42",
                ),
            )   
        ),
        "returnUrl" => "http://localhost/",
        "cancelUrl" => "http://localhost/",
        "requestEnvelope" => $this->envelope
    );

    $response = $this->_paypalSend($createPacket, "Pay");
    $paykey =   $response["payKey"];
    #echo "<pre>";
    #print_r($response);
    //echo ;
    #echo "</pre>";

    // SET PAYMENT DETAILS
    $detailsPacket = array(
        "requestEnvelope" => $this->envelope,
        "payKey"    =>  $paykey,
        "receiverOptions"   =>  array(
            array(
                "receiver"  => array("email"    =>  "test@gmail.com"),
                "invoiceData"   =>  array(
                    "item"  =>  array(
                        array(
                            "name"  => "product 1",
                            "itemCount" => "1",
                            "itemPrice" => "1",
                            "price" => "1.00",
                            "identifier"    => "p1",
                            "totalTax"  =>  "0.00",
                            "totalShipping" =>  "0.00",
                        ),
                        array(
                            "name"  => "product 1",
                            "itemCount" => "1",
                            "itemPrice" => "1",
                            "price" => "1.00",
                            "identifier"    => "p2",
                            "totalTax"  =>  "0.00",
                            "totalShipping" =>  "0.00",
                        )
                    )
                )
            ),
            array(
                "receiver"  => array("email"    =>  "test2@gmail.com"),
                "invoiceData"   =>  array(
                    "item"  =>  array(
                        array(
                            "name"  => "product 1",
                            "itemCount" => "1",
                            "itemPrice" => "1",
                            "price" => "1.00",
                            "identifier"    => "p1",
                            "totalTax"  =>  "0.00",
                            "totalShipping" =>  "0.00",
                        ),
                        array(
                            "name"  => "product 1",
                            "itemCount" => "1",
                            "itemPrice" => "1",
                            "price" => "1.00",
                            "identifier"    => "p2",
                            "totalTax"  =>  "0.00",
                            "totalShipping" =>  "0.00",
                        )
                    )
                )
            ),
        )
    );

    $response = $this->_paypalSend($detailsPacket,"SetPaymentOptions");
    #echo "<pre>";
    #print_r($response);
    #echo "</pre>";

    $dets   =   $this->GetPaymentOptions($paykey);
    #echo "<pre>";
    #print_r($dets);
    #echo "</pre>";
    header("Location: ".$this->paypalUrl.$paykey);
}

}

谢谢和问候,
莫希特·辛格

4

0 回答 0