Handlng Paypal付款API回复

时间:2016-06-23 17:11:09

标签: php paypal

我希望这是提出这个问题的正确位置,但我似乎无法在文档中找到答案。

我正致力于使用PHP和Paypal实施支付解决方案。

处理PAYPAL帐户付款时,我按照此处所述的步骤操作: Accepting a Paypal Payment

完成这些步骤不是问题。我从成功的交易中获得了预期的结果。

我的问题是处理错误/付款失败。

根据文档,SALE状态可以是:

Possible values: completed, partially_refunded, pending, refunded, denied.

什么会导致它成为待定?此外,SALE状态是否正在等待导致PAYMENT状态失败?

我试图了解这两种状态如何相互融合并相互影响。目的是妥善处理付款。知道什么时候被批准/拒绝,所以我可以相应地处理它。

现在,我的测试代码如下:

$response = executePaypalPayment($token, $payer_id, $payment_id);

    //Get the state of the payment
    $payment_state = $response->state;

    //Get the state of the sale
    $sale_state = $response->transactions[0]->related_resources[0]->sale->state;

    if($payment_state == "approved" && $sale_state == "completed"){
        //Everything was successful
        $message = 'Your order was placed successfully! A confirmation email has been sent to the email address provided.';
        displayOrderScreenMessage($message);

    } else {
        //Something went wrong
        if($payment_state !== "approved"){
            //payment failed
            $message = "Unable to process payment. Please try again.";
            displayOrderScreenMessage($message, true, true);
        }

    }

问题是,我不知道如何确定付款的状态。任何帮助表示赞赏。谢谢!

0 个答案:

没有答案
相关问题