'sandbox' ); $c-6ren">
gpt4 book ai didi

PayPal Rest API - 使用的端点

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:23 25 4
gpt4 key购买 nike

在我的开发环境中,我可以正确地将 Rest API 用于沙盒站点:

    $sdkConfig = array(
"mode" => 'sandbox'
);

$cred = new OAuthTokenCredential(
$SANDBOX_clientId,
$SANDBOX_clientSecret
);

$access_token = $cred->getAccessToken($sdkConfig);

当使用带有 Live Keys 的相同代码和经过验证的 Live 帐户时:

    $sdkConfig = array(
"mode" => 'live'
);

$cred = new OAuthTokenCredential(
$LIVE_clientId,
$LIVE_clientSecret
);

$access_token = $cred->getAccessToken($sdkConfig);

我得到这个错误:访问时http响应码401 https://api.sandbox.paypal.com/v1/oauth2/token

PayPal REST API 如何知道要访问哪个端点?

我没有在沙盒或实时调用中指定端点,也没有使用 Bootstrap 或 ini 文件。该帐户已通过验证和批准。

最佳答案

我推荐的最佳方法是创建一个类似于 https://gist.github.com/jaypatel512/a2b037ab5ddc51fa7280 所示的 ApiContext 对象

<?php

// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';

// 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret
// https://developer.paypal.com/webapps/developer/applications/myapps
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID
'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret
)
);

// Step 2.1 : Between Step 2 and Step 3
$apiContext->setConfig(
array(
'mode' => 'live',
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'FINE'
)
);


// 3. Lets try to save a credit card to Vault using Vault API mentioned here
// https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card
$creditCard = new \PayPal\Api\CreditCard();
$creditCard->setType("visa")
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");

// 4. Make a Create Call and Print the Card
try {
$creditCard->create($apiContext);
echo $creditCard;
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo $ex;
}

关于PayPal Rest API - 使用的端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31006459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com