php - Paypal PHP SDK 支付状态

标签 php paypal paypal-sandbox payment

我正在使用 paypal php sdk。我有以下代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require __DIR__  . '/vendor/PayPal-PHP-SDK/autoload.php';

$dev_ClientID = 'xxxxxxxxxx';
$dev_ClientSecret = 'xxxxxxxxxx';

$apiContext = new \PayPal\Rest\ApiContext(
        new \PayPal\Auth\OAuthTokenCredential(
             $dev_ClientID     
            ,$dev_ClientSecret     
        )   
);

$payer = new \PayPal\Api\Payer();
$payer->setPaymentMethod('paypal');

$amount = new \PayPal\Api\Amount();
$amount->setTotal('1.00');
$amount->setCurrency('USD');
$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount);

$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls->setReturnUrl("https://www.somedomain.com/paypal_success.php")
    ->setCancelUrl("https://www.somedomain.com/paypal_cancel.php");

// Create the WebProfile
$presentation = new \PayPal\Api\Presentation();
$presentation->setLogoImage("http://www.yeowza.com/favico.ico")
    ->setBrandName("YeowZa! Paypal")
    ->setLocaleCode("US");

$inputfields = new \PayPal\Api\InputFields();
$inputfields ->getNoShipping(1);

$webProfile = new \PayPal\Api\WebProfile();
$webProfile
   ->setName('somename' . uniqid())
   ->setInputFields($inputfields)
   ->setTemporary(true);

$webProfileId = $webProfile->create($apiContext)->getId();

$payment = new \PayPal\Api\Payment();
$payment->setExperienceProfileId($webProfileId);

$payment->setIntent('sale')
    ->setPayer($payer)
    ->setTransactions(array($transaction))
    ->setRedirectUrls($redirectUrls);

try {
    $payment->create($apiContext);
    echo "\n\nRedirect user to approval_url: " . $payment->getApprovalLink() . "\n";
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
    // This will print the detailed information on the exception.
    echo $ex->getData();
}
?>

我收到了付款链接,但我仍然看到了送货信息。

我已将 getNoShipping 定义为 true,可能 Hook 的网络配置文件有误。所以这是一回事。我不确定的第二件事是这个。

我通过了付款并被重定向回 paypal_success.php,其中包含 paymentId、token 和 PayerID。我将如何使用这些来接收有关交易的信息。我希望确保它确实发生了。

我尝试了以下方法:

$paymentId = $_GET["paymentId"];
$token = $_GET["token"];
$PayerID = $_GET["PayerID"];
echo "paymentId: " . $paymentId . "<br>";
echo "token: " .$token . "<br>";
echo "PayerID: " .$PayerID . "<br>";



$curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/$paymentId");
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 ' . $token,
    'Accept: application/json',
    'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);


var_dump($result);

结果如下:

{ ["error"]=> string(13) "invalid_token"["error_description"]=> string(35) " token 签名验证失败"}

将感谢提供的任何帮助。 谢谢

最佳答案

您可以使用以下电话获取付款明细

$payment_details = PayPal\Api\Payment::get($paymentId, $apiContext);

此处 $apiContext 是您用于进行交易的 api 凭据。

此外,如果您想使用 curl,则使用以下端点 $curl = curl_init("https://api.sandbox.paypal.com/v1/checkout/orders/$paymentId"); 获取付款详情不正确,您应该使用此端点$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/$paymentId");

关于php - Paypal PHP SDK 支付状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198576/

相关文章:

php - 交响乐团 : creating invalid MySQL code?

php - 按日期第几行对sql输出进行排序

ruby-on-rails - 在不成功的 Braintree 交易期间返回参数/信用卡信息

symfony - JMSPaymentPaypalBundle 空白订单摘要

php - 使用 Zend Framework 忽略文件上传的空实例?文件因此无法上传

php - 允许用户使用 php mysql 在三种类型之间进行选择的搜索页面

PayPal 回复漏税

Paypal 没有覆盖返回 URL?

Paypal BuyNow - 使用 returnUrl 参数获取而不是 POST

php - 我们很抱歉。该卖家不接受以您的货币付款