Paypal PHP SDK REST is not returning any “success” variable

不羁的心 提交于 2019-12-25 08:48:03

问题


I make basic PayPal payment on sandbox, following instructions on official samples here:

  • CreatePaymentUsingPayPal

  • Execution

The problem appears when my Execution service is getting request from paypal server. After dumping $_GET variables I can see something like:

array:3 [▼
  "paymentId" => "PAY-9HM25571EF136871GLEWZM6A"
  "token" => "EC-6VX65808WU776334M"
  "PayerID" => "2ADP8W2S9ST8Z"
]

So there is no variable called "success". If payment ended without success I should get "success": false. I have no idea what is going on and how can I fix it.

Please for help,

Arthur.


回答1:


The variable you're looking for is the state. The three possible values: created, approved, failed. Here's what the raw json looks like.

{
    "id": "PAY-XXXXXXXXXXXXXXXXXXXXXXXX",
    "intent": "sale",
    "payer": {},
    "cart": "",
    "transactions": [{}],
    "state": "approved",
    "create_time": "2017-08-14T15:38:12Z",
    "links": [{}]
}

If you're creating the payment, to send the buyer to authorize the payment, you'd want state to be created. If you're executing the payment, you want state to be approved.

The $payment and $result objects represent the json responses as objects. Running $result->getStatus() should return the status string.




回答2:


The "success" is not going to come automatically. When you make your initial POST v1/Payments call (Create Payment) you need to include the below

$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
    ->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");

check this out [http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/CreatePaymentUsingPayPal.html][1]

basically just make sure you specify your success return URL as something like www.mysite.com/successpage.html?success=true . PYPL will append paymentId=PAY67S97196TG1078736LIKMI4Q&token=EC37412549V2519404X&PayerID=DNZQ8C57C7P6Q



来源:https://stackoverflow.com/questions/44267179/paypal-php-sdk-rest-is-not-returning-any-success-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!