I've implemented PayPal Billing subscription using PayPal-PHP-SDK, everything is working fine as expected, the user can cancel the subscription from the application with this code.
$agreementStateDescriptor = new AgreementStateDescriptor();
$agreementStateDescriptor->setNote("Suspending the Agreement.");
$agreement->suspend($agreementStateDescriptor, $apiContext);
But if the user cancel the subscription from his PayPal account, my application will not be notified for it, how it can be addressed? is there any webhook as Stripe or something.
https://github.com/paypal/PayPal-PHP-SDK/
Thanks
you need to create a Paypal webhook for your app.
Set an URL (accessible URL) i.e. yourdomain/paypal/resolver
then register event BILLING.SUBSCRIPTION.CANCELLED.
Once the user cancel the agreement from Paypal, the webhook for BILLING.SUBSCRIPTION.CANCELLED event is activated and send a request to your site.
FYI, the samples provided from this link http://paypal.github.io/PayPal-PHP-SDK/sample/ are pretty much useful
Related
I am using the PayPal API to create a Webhook, and not the Developer site. When is the best time to do this? Do I create the webhook before the payment is created, after the payment is created, or after the payment is executed? According to the API documentation, the webhook needs to be created only once in the lifetime of the app. What happens if a new webhook is created each time the app is used?
What I have:
processPayment: the payment details are defined, the payment is created, the user is redirected to PayPal.
executePayment: the user is returned from PayPal, the payment is executed.
On notify:
verifyPayment: calls a function to validate Webhook signature.
Post-processing in the Site's database.
P.S. Where/how is the webhook Id generated?
Webhook needs to be created before making a payment transaction if you want to get notified of the payment. If there are multiple Webhooks configured on your app and if you have same set of events subscribed on both, you would receive notifications on both Webhooks.
Thanks!
I am working with the PHP version of the PayPal REST API within Sandbox environment.
I was able to create and execute a payment, that was approved using a Sandbox PayPal Account. The payment was made using MANUAL_BANK_TRANSFER, meaning that there is not enough money on the PayPal Account. The user would have to transfer money to his PayPal account first. Thus the payment was created as Pending.
So far so good. After creating/approving the payment I logged into the PayPal account of the Sandbox user and canceled the payment. I assumed, that my system would get notified of this action via another Webhook Event. This was not the case. I received no event at all.
I created the Webhook Event as wildcard (all events) and the PAYMENT.SALE.PENDING event was received without any problem. Thus there should be no problem with receiving other events. But even one hour after the payment was canceled I have not received any event.
I assume that I should get notified of a canceled payment, but I don't know if this is really the case. The PayPal docu does not describe in detail which events will be triggered by which actions.
So, is there something wrong with my Webhook config or is there really no event on canceled payments?
When refunding a payment via the paypal-account/paypal-backend, you don't get notified via webhooks. Webhooks only work when the action was invoked via the REST-API. The only possible thing you could do is implementing an INP, but I haven't tested it if this will work.
I'm trying to get notified via webhooks when a simple payment is made, however I don't receive any request from paypal on the specified URL.
Here is what I've done:
I have 2 sandbox accounts: Facilitator and Buyer
Create an app (sanbox mode) for the facilitator account
Add a webhook URL in that app
Login into sanbox.paypal.com with the sandbox facilitator username and password
Generate a buy now button with a test product
Paste the button code on my page and make a purchase with the sanbox Buyer account
In developer dashboard the payment is received if I go to Sandbox -> Notifications: "Notification of Payment Received from test buyer", but the webhook page on my server is not called. I know this because the php script creates a txt file every time the page is called.
Also if I go to Developer Account -> Webhook Notifications and select the app I have this message: You don't have any events for the selected application
NOTE: If I add the URL in the webhook simulator everything works great.
Am I doing something wrong? Do I have to connect the app with the buy now button?
Thanks
Webhooks is only used for REST payments. However for Paypal buttons created in PP account, you need to use Paypal IPN. Here is the guide for IPN and IPN script for your reference.
Suppose we have PayPal sandbox account, with created Application for REST API calls.
In our application we use PayPal Pay Buttons, to redirect customer to PayPal site. Customer pays and returning back to site, where we checking status and setting external reference to transaction.
For this operations we're using not Application's credentials, but accounts - email, password and username. After this we're accepting IPN messages from PayPal to track status, using the same credentials.
Then we have a button Refund, pressing this button will make a request to REST API to PayPal with Application's access information (clientId and clientSecret). This part built on top of PayPal PHP SDK.
When I try to execute a call - PayPal returning 404 error. I suppose the payment is not visible to Application.
Better vision of what credentials and where are used:
PayPal account:
Live:
email
password
username
Test:
email-test
password-test
username-test
Application:
Live:
clientId
clientSecret
Test:
clientIdTest
clientSecretTest
For button I use: email-test, username-test, password-test
Then I get $transactionId. And using it in code:
$api = new ApiContext(new OAuthTokenCredential($clientIdTest, $clientSecretTest));
$ppAmount = new Amount();
$ppAmount->setCurrency('USD')
->setTotal(33.15);
$ppRefund = new Refund();
$ppRefund->setAmount($ppAmount);
$ppSale = new Sale();
$ppSale->setId($transactionId);
$ppSale->refund($ppRefund, $apiContenxt);
And I get 404. As you can see I use test credentials for buttons and for REST call, but for some reason getting 404.
Thanks in advance.
As far as I know only payments made via REST API can be refunded using the REST API, meaning if you created the payment via a button or a different API you cannot use REST refund.
REST refund expects a sale_id (which is generated when you "execute" a REST payment) in the Sale entity.
I have integrated PayPal merchant account to the website , m doing it for a client
People can sign up to the website after subscribing and hence paying thru PayPal .we have recurring payments. But if people unsubscribe from the site their access to the site is closed but my issue is if people don't click the unsubscribe on the site but just cancel the recurring payment from their own PayPal accounts how would I cancel their subscription on the site.
Please suggest some PHP code or idea to cancel the subscription.
Thanks in Advance, vikas tyagi
i got it a perfect solution of my question
In addition to email notification, PayPal can send you the transaction data (also called Instant Payment Notification) to a specific url. With Instant Payment Notification, PayPal sends payment notification messages with encrypted code to the specified URL for each payment you receive. Follow the instructions below to setup Instant Payment Notification.
Go to the PayPal website and log in to your account.
Click "Profile" at the top of the page.
Click "Instant Payment Notification Preferences" in the Selling Preferences column.
Click "Edit IPN Settings."
Enter the notification URL and select "Receive IPN messages."
Click "Save."
You can send customized emails from the Instant Payment Notification data. Please see http://paypaltech.com/SG2 for sample scripts.
we can customize sample script code according our need.
Add the logic to your Paypal IPN handler, Paypal should send a notification to your server via IPN with that information.
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECRecurringPayments
Another idea could be queryiing paypal API and see if the subsscription is still active when the user logs in.
But im sure IPN handler is easier to implement