PayPal自适应付款PHP

时间:2014-04-22 13:24:44

标签: php curl paypal paypal-adaptive-payments

我最近尝试使用PHP向PayPal发出API请求以支付多个帐户,但到目前为止我没有运气。

`

class PayPal
{
    public $_headers = array();
    public $_config = array();
    public $_data = array();

    public function __construct()
    {
        if (!in_array('curl', get_loaded_extensions()))
        {
            trigger_error("CURL extension is not installed or enabled", E_USER_ERROR);
        }
    }

    public function update_headers(array $credentails)
    {
        $this->_headers = $credentails;
        return $this;
    }

    public function update_config(array $config)
    {
        $this->_config = $config;
        return $this;
    }

    public function pay($data, $call)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->get_url());
        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, $data);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers);
        return curl_exec($ch);
    }

    public function split_pay()
    {
        // create the pay request
        $this->_data = array(
            "actionType" =>"PAY",
            "currencyCode" => "USD",
            "receiverList" => array(
                "receiver" => array(
                    array(
                        "amount"=> "1.00",
                        "email"=>"******@gmail.com"
                    ),
                    array(
                        "amount"=> "2.00",
                        "email"=>"*********.co.uk"
                    ),
                ),
            ),
            "returnUrl" => "http://test.local/payments/confirm",
            "cancelUrl" => "http://test.local/payments/cancel",
            "requestEnvelope" => array(
                "errorLanguage" => "en_US",
                "detailLevel" => "ReturnAll",
            ),
        );

        return $this->pay($this->_data, "PAY");
    }

    private function get_url()
    {
        if (empty($this->_config))
        {
            trigger_error("You have not setup the config", E_USER_ERROR);    
        }

        return $this->_config['url'];
    }

    public function call_headers()
    {
        if (empty($this->_headers))
        {
            trigger_error("You have not set any headers", E_USER_ERROR);    
        }

        print_r($this->_headers);
    }
}

>`

这是我创建的一个类文件,它非常粗糙但不起作用。这是一些更多的代码。 `负载>库('贝宝&#39); $ pp =新PayPal();

        //Bring me the money!
        //Headers for paypal
        $headers = array(
            "X-PAYPAL-SECURITY-USERID: ********",
            "X-PAYPAL-SECURITY-PASSWORD: *********",
            "X-PAYPAL-SECURITY-SIGNATURE: **********",
            "X-PAYPAL-REQUEST-DATA-FORMAT: NV",
            "X-PAYPAL-RESPONSE-DATA-FORMAT: NV",
            "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T"
        );

        $config = array(
            'url' => 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay',
            'username' => '********',
            'password' => '********',
            'signature' => '********',
            'app_id' => 'APP-80W284485P519543T',
        );

        $pp->update_headers($headers)->update_config($config);
        print_r($pp->split_pay());

&GT?; ` 这个回复让我回来了。 responseEnvelope.timestamp = 2014-04-22T06%3A15%3A49.821-07%3A00&安培; responseEnvelope.ack =失败&安培; responseEnvelope.correlationId = b3d05fe547e22&安培; responseEnvelope.build = 10680030&安培;错误(0)= .errorId&580001安培;错误(0 )。域= PLATFORM&安培;错误(0).subdomain =应用&安培;错误(0).severity =错误&安培;错误(0).category =应用&安培;错误(0).message =无效+请求%3A +%7B0%7D < / p>

有没有人知道为什么会这样?

0 个答案:

没有答案