duanou9739 2014-11-27 21:57
浏览 31

MALFORMED_REQUEST尝试与paypal沟通

I'm having trouble just sending my first API call to PayPal.

I'm hoping its just simple syntax that I got wrong.

The error I'm getting:

"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
else
{
    $json = json_decode($result);

    $sAccessToken = $json->access_token;
    $sTokenType = $json->token_type;
    $sAppID = $json->app_id;
    print_r($json);
}
curl_close($ch);

$ch2 = curl_init();

//curl -v https://api.sandbox.paypal.com/v1/payments/payment 
curl_setopt($ch2, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");

//-H "Content-Type:application/json" \
//-H "Authorization: Bearer <Access-Token>" \
curl_setopt($ch2, CURLOPT_HTTPHEADER, array(
    "Content-Type:application/json",
    "Authorization: Bearer ".$sAccessToken,
));



$payer = array(
    'payment_method'        => 'credit_card',
    'funding_instruments'   => array(
                    'credit_card'       => array(

                            'number'            => "4417119669820331",
                            "type"              => "visa",
                            "expire_month"      => "11",
                            "expire_year"       => "2018",
                            "cvv2"              => "874",
                            "first_name"        => "Betsy",
                            "last_name"         => "Buyer",
                            "billing_address"   => array(
                                    "line1"             => "111 First Street",
                                    "city"              => "Saratoga",
                                    "state"             => "CA",
                                    "postal_code"       => "95070",
                                    "country_code"      => "US"
                            ),
                    ),
            ),
);

$params = array(
    'intent'    => 'sale',
    'payer'     => $payer,
    'transactions'  => array(array(
                "amount"         =>"7.47",
                "currency"      =>"USD",
                "details"       => array(
                                    "subtotal"=>"7.41",
                                    "tax"=>"0.03",
                                    "shipping"=>"0.03"
                ),
                "description" => "This is the payment transaction description."
    )
));

curl_setopt($ch2, CURLOPT_POST, true );
curl_setopt($ch2, CURLOPT_POSTFIELDS, json_encode( $params ) );
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true );

$response2 = curl_exec( $ch2 );
$errrors2 = curl_error($ch2);

print_r($response2." / ");
print_r($errrors2);
curl_close($ch2);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 shape_predictor_68_face_landmarks.dat
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制