Paypal API错误:10400

时间:2015-10-10 19:02:41

标签: php paypal

您好我遇到了paypal API的问题 所以我为GetExpressCheckoutDetails设置了一切,现在我正在尝试DoExpressCheckoutPayment。

以下是我遇到的错误:

array (size=9)
  'TIMESTAMP' => string '2015-10-10T18:56:25Z' (length=20)
  'CORRELATIONID' => string '1ad7e8dba8063' (length=13)
  'ACK' => string 'Failure' (length=7)
  'VERSION' => string '98.0' (length=4)
  'BUILD' => string '18308778' (length=8)
  'L_ERRORCODE0' => string '10400' (length=5)
  'L_SHORTMESSAGE0' => string 'Transaction refused because of an invalid argument. See additional error messages for details.' (length=94)
  'L_LONGMESSAGE0' => string 'Order total is missing.' (length=23)
  'L_SEVERITYCODE0' => string 'Error' (length=5)

这是我的代码:

我的Paypal课程:

<?php

class Paypal{

    private $user = 'xxxxxx';
    private $pwd = '5xxxxxx';
    private $signature = 'xxxxxx';
    private $endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
    public $errors = array();


    public function __construct($user = false, $pwd = false, $signature = false, $prod = false){
        if($user){
            $this->user = $user;
        }
        if($pwd){
            $this->pwd = $pwd;
        }
        if($signature){
            $this->signature = $signature;
        }
        if($prod){
            $this->endpoint = str_replace('sandbox.','', $this->endpoint);
        }
    }


    public function request($method, $params){
        $params = array_merge($params, array(
            'METHOD' => 'SetExpressCheckout',
            'VERSION' => '98.0',
            'USER' => $this->user,
            'SIGNATURE' => $this->signature,
            'PWD' => $this->pwd
        ));

        $params = http_build_query($params);
        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => $this->endpoint,
            CURLOPT_POST => 1,
            CURLOPT_POSTFIELDS => $params,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
            CURLOPT_VERBOSE => 1
        ));


        $response = curl_exec($curl);
        $responseArray = array();
        parse_str($response, $responseArray);
        if(curl_errno($curl)){
            $this->errors = curl_error($curl);
            curl_close();
            return false;
        }else{
            if($responseArray['ACK'] == 'Success'){
                return $responseArray;
            }else{
                $this->errors = $responseArray;
                curl_close($curl);
                return false;
            }
        }

    }



}

Process.php

<?php
/*******************
TO DO:
SECURISER l'acces a la page 
$_GET['token'] doit etres defini
$_GET['PayerID'] aussi
*******************/
require 'paypal.php';

$paypal = new Paypal();
$response = $paypal->request('GetExpressCheckoutDetails', array(
    'TOKEN' => $_GET['token']
));

if($response){
}else{
    var_dump($paypal->errors);
    die();
}

$response = $paypal->request('DoExpressCheckoutPayment', array(
    'TOKEN' => $_GET['token'],
    'PAYERID' => $_GET['PayerID'],
    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
    'PAYMENTREQUEST_0_AMT' => $response['PAYMENTINFO_0_AMT'],
    'PAYMENTREQUEST_0_ITEMAMT' => $response['PAYMENTINFO_0_AMT'],
    'PAYMENTREQUEST_0_CURENCYCODE' => 'EUR',
    'L_PAYMENTREQUEST_0_QTY0' => 1,
    'L_PAYMENTREQUEST_0_AMT0' => 12.0,
    'L_PAYMENTREQUEST_0_NAME0' => "Générateur d'énergie quatique",
    'L_PAYMENTREQUEST_0_NUMBER0' => 0,
    'L_PAYMENTREQUEST_0_QTY1' => 2,
    'L_PAYMENTREQUEST_0_AMT0' => 30.50,
    'L_PAYMENTREQUEST_0_NAME0' => "Hyperdrive T14",
    'L_PAYMENTREQUEST_0_NUMBER0' => 1

));

if($response){
    var_dump($response);
}else{
    var_dump($paypal->errors);
}

付款后,每当我通过PayPal重定向到process.php时,我都会得到这个:

array (size=9)
  'TIMESTAMP' => string '2015-10-10T18:56:25Z' (length=20)
  'CORRELATIONID' => string '1ad7e8dba8063' (length=13)
  'ACK' => string 'Failure' (length=7)
  'VERSION' => string '98.0' (length=4)
  'BUILD' => string '18308778' (length=8)
  'L_ERRORCODE0' => string '10400' (length=5)
  'L_SHORTMESSAGE0' => string 'Transaction refused because of an invalid argument. See additional error messages for details.' (length=94)
  'L_LONGMESSAGE0' => string 'Order total is missing.' (length=23)
  'L_SEVERITYCODE0' => string 'Error' (length=5)

我做错了什么?

2 个答案:

答案 0 :(得分:0)

来自paypal api error codes

10400
  

由于参数无效,交易被拒绝。看到   其他错误消息以获取详细信

     

缺少订单总数

基本上,你错过了OrderTotal

答案 1 :(得分:0)

按照您的代码我认为参数L_PAYMENTREQUEST_0_AMT0设置了两次,价格不同,检查只设置一次