免签约即时到帐支付接口

PayPal v1和v2使用php curl获取交易订单相关内容

本文介绍了贝宝(PayPal)使用php curl获取交易订单相关内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着ECSHOP插件网来一起学习吧!
在成功完成PayPal付款后,我得到了信息如下:
{
    "response": {
        "state": "approved",
        "id": "PAY-6PU626847B288842SKPEWXZD",
        "create_time": "2022-07-18T18:46:55Z",
        "intent": "sale"
    },
    "client": {
        "platform": "Android",
        "paypal_sdk_version": "2.11.0",
        "product_name": "PayPal-Android-SDK",
        "environment": "mock"
    },
    "response_type": "payment"
}
{
    "short_description": "Pay List Payment",
    "amount": "100",
    "intent": "sale",
    "currency_code": "USD"
}
然后我使用PAY-6PU626847B288842SKPEWXZD支付密钥,并使用带有以下代码的PHP curl GET请求获取交易明细.
$accessToken='<Access Token>';
$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/PAY-6PU626847B288842SKPEWXZD");
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $accessToken,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;
点击后,我得到以下响应,但未获得交易明细.
{"name":"INVALID_RESOURCE_ID","message":"The requested resource ID was not found","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"ppc1e3a55f10e"}
以下内容对大家有用
1.进行CURL发布以获取访问令牌
$uri = 'https://api.sandbox.paypal.com/v1/oauth2/token';
//for live production use $uri = 'https://api.paypal.com/v1/oauth2/token';
$clientId = '<YOUR-CLIENT-ID-HERE>';
$secret = '<YOUR-SECRET-HERE>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
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);
$access_token = '';
if (empty($result))
{
    die("Error: No response.");
}
else
{
    $json = json_decode($result);
    $access_token = $json->access_token;
}
curl_close($ch);
2.进行CURL发布以获取交易详细信息,例如付款状态,金额,日期等.
$url = "https://api.sandbox.paypal.com/v2/payments/captures/<YOUR-PAYMENT-ID-HERE>";
$accessToken = $access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $accessToken,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;
3.进行CURL发布以获取更多交易详细信息(这比第2步提供了更详细的响应。因此,您可以使用此方法代替第2步
$url = "https://api.sandbox.paypal.com/v2/checkout/orders/<YOUR-order-ID-HERE>";
$accessToken=$access_token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $accessToken,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
print_r($response);
exit;
这篇关于贝宝PayPal使用php curl使用付款键获取交易明细的文章就介绍到这了,希望我们推荐的代码对大家有所帮助,也希望大家多多支持ECSHOP插件网

本文原创地址:https://www.ecshopok.com/article-932.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉

文章评论

暂无评论,来发表一个吧

发表 取消
充值有惊喜 ECSHOP插件网微信客服edait_cn