Reputation: 41
I'm developping a payment system which is using paypal's rest api. So far so good, I can do payments in sandbox mode without any problems.
Now I need paypal to notify me on certain events ... which is why I wanted to use webhooks.
I create a little script which just write the received body into a text file to do some debugging. Then I did create the webhook in paypal's dev site. The Webhook simulator is working fine and the json string coming from paypal is fine. However, when I just do a payment through my site, there is no webhook. They don't seem to be called, since it doesn't show any webhook events in developer.paypal.com ...
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$payment = new PPayment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
I'm using the payment method "paypal" and the "sale" intent. That should be working in theory.
Anyone any idea ? I did some research and found that the sandbox is bugged from time to time ... but this is a crucial feature that I need to test.
Hope you guys can help.
Greetings
Upvotes: 0
Views: 1523
Reputation: 670
As @MollocH has figure out, in order to trigger PayPal's webhooks you must approve the payment once you redirected to your website.
$payerId = // 'PayerID' from the GET query;
$paymentId = // 'paymentId' from the GET query;
$apiContext = // you know where to get this from
$payment = Payment::get($paymentId, $apiContext);
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
try
{
$payment = $payment->execute($execution, $context);
// redirect user to success message or so
}
catch(\Exception $error)
{
}
Upvotes: 0
Reputation: 41
So I found the problem:
basically you have to approve the payment before you get a notification.
What is wrong with my paypal process to receive webhook notifications?
On your return Site, you just need to send an approval and there your webhook is triggered!
Upvotes: 2