我的贝宝接收Webhook通知的流程有什么问题? [英] What is wrong with my paypal process to receive webhook notifications?

查看:116
本文介绍了我的贝宝接收Webhook通知的流程有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我到目前为止所做的,而且没有用,我将感谢您在此问题上的任何帮助:

So this is what i did so far and it doesn't work, i will appreciate any help on the matter:

我的目标是发回在我的Paypal沙箱帐户中发生的所有Webhook事件.

my goal is to post back any webhook event that occur in my paypal sandbox account.

所以我有2个帐户, 属于收款人的人,称为协助人", 属于买方"的一位,

So i have 2 accounts, one that belongs to the receiver of the money, call it "facilitator", one that belong to the "buyer",

现在,在我的帐户中,有一个Sandbox webhooks配置,因此我输入了以下内容: https://csdieuqkzo.localtunnel.me

Now in my account,there is a Sandbox webhooks configuration, so i entered the following: https://csdieuqkzo.localtunnel.me

不用说这来自 localtunnel.me .

因此,在我的项目中,我使用api进行了简单的销售...这是完整的创建销售过程:

So in my project, i do a simple sale using the api... this is the full create sale process:

$payer = new Payer();
 $payer->setPayment_method('paypal');

 //dd($payer);
 $item = new Item();

 $item->setQuantity('1');
 $item->setName('benny');
 $item->setPrice('7.41');
 $item->setCurrency('USD');
 $item->setSku('blah');
 // //var_dump($item);

 $items = new ItemList();
 $items->addItem($item);
 //var_dump($items);

$amountDetails = new Details();
$amountDetails->setSubtotal('7.41');
$amountDetails->setTax('0.03');
$amountDetails->setShipping('0.03');

$amount = new Amount();
$amount->setCurrency('USD');
$amount->setTotal('7.47');
$amount->setDetails($amountDetails);

$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');
$transaction->setItemList($items);

// echo '<pre>';
// print_r($transaction);


$RedirectUrls = new RedirectUrls();
$RedirectUrls ->setReturnUrl('https://csdieuqkzo.localtunnel.me/#/pricing');
$RedirectUrls ->setCancelUrl('https://csdieuqkzo.localtunnel.me/#/');

$payment = new Payment();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));
$payment->setRedirectUrls($RedirectUrls);

// echo '<pre>';
// print_r($payment);
// dd();
$response = $payment->create($this->apiContext)->toarray();

Session::put('pay_id',$response['id']);

return Response::json($response);

此后,将重定向到贝宝(PayPal),获得批准,当它回到我的网站时,它执行以下操作:

After this there is a redirect to paypal, approval and when it comes back to my site, it excute with the following:

  $payerId =  Input::get('payerId');

$payment = Payment::get(Session::get('pay_id'), $this->apiContext);

//return $payerId;

 $paymentExecution = new PaymentExecution();
 $paymentExecution->setPayer_id($payerId);

 $approval = $payment->execute($paymentExecution, $this->apiContext)->toarray();

 return Response::json($approval);

然后有一个对象说这笔交易的状态已获批准,超级,但是我看不到我之前定义的webhook url的任何帖子...现在我如何对其进行测试了?

Then an object is coming in saying the state of this transaction is approved, super, but i don't see any post to the webhook url i defined earlier...Now how did i test it?

我为根目录的post方法(在laravel中)写了一个简单的脚本:

I wrote a simple script to the post method of my root (in laravel):

Route::post('/',function(){
    $myfile = fopen("bennyfile.txt", "a") or die("Unable to open file!");
     $txt = "\nouterequested";
     fwrite($myfile, $txt);
     fclose($myfile);
});

每当发布请求到达以下URL时(在我的情况下,即发布到以下根目录的链接): https://csdieuqkzo.localtunnel.me

Means whenever a post request is coming to the following url (in my case, a post to the root of:https://csdieuqkzo.localtunnel.me

我只想添加一行,仅此而已...但是它什么也不会更新!... 例如,如果我向邮递员发出到同一地点的邮寄请求,那么一切都很好,但是当销售被批准或其他任何动作时,则什么也没有发生.

I just want to add a line, that's it...but it doesn't update anything!... for example if i do a post request from postman to the same place, all is good, but when a sale is approved, or any other action, nothing is happening.

为什么?

推荐答案

这是一个Paypal文档,可帮助您了解webhooks的工作原理.

This is a paypal document which helps you understand how webhooks works.

https://developer.paypal.com/docs/integration /direct/rest-webhooks-overview/

webhooks是http回调机制,理想情况下,您需要一个有效的URL作为您的webhooks终结点来测试PayPal发布的webhooks通知消息.如果您是使用Paypal钱包进行销售的,那么您应该在端点处获取JSON格式的PayPal的webhooks通知消息. webhooks还不支持直接信用卡保护套.

webhooks is http call back mechanism, ideally, you will need a valid url as your webhooks endpoint to test the webhooks notification message posted by PayPal. If you did sale using paypal wallet, you should get PayPal's webhooks notification message in JSON format at your endpoint. webhooks doesn't support direct credit card case yet.

如果要在本地测试您的侦听器脚本,则可以使用邮差工具将示例消息发布到本地url并进行测试.

If you want to test your listener script on local, you can use postman tool to post the sample message to your local url and test.

这篇关于我的贝宝接收Webhook通知的流程有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆