My problem is that billing agreements are successfully executed even if the setup fee is not paid. Looking at the logs, the IPN event notifiying that the setup fee failed and the agreement is cancelled typically takes 5-10 minutes to arrive, which is an insane amount of delay.
I am using the official PayPal PHP SDK at https://github.com/paypal/PayPal-PHP-SDK. It was deprecated a month ago, but its replacement is marked "not ready for production".
Billing plan details, with the intent to charge a $29.99/yr subscription. Setup fee is used to guarantee initial payment.
Per the 2 step process documented in https://paypal.github.io/PayPal-PHP-SDK/sample/, with the wrapping try/catch blocks removed for legibility:
// Step 1: https://paypal.github.io/PayPal-PHP-SDK/sample/doc/billing/CreateBillingAgreementWithPayPal.html use PayPal\Api\Agreement; use PayPal\Api\MerchantPreferences; use PayPal\Api\Payer; use PayPal\Api\Plan; /** * @var \PayPal\Rest\ApiContext $apiContext */ $plan = Plan::get('EXAMPLE-PLAN-ID', $apiContext); $agreement = new Agreement(); date_default_timezone_set('America/Los_Angeles'); $agreement->setName($plan->getName()) ->setDescription($plan->getDescription()) // I'm not sure why +1 hour is used here, but that's how it is in the codebase. ->setStartDate(date('c', strtotime("+1 hour", time()))); $agreement->setPlan($plan); /** *
I'm at a loss for what I'm doing wrong that would cause the billing agreement to execute even without the setup fee being paid. Help would be appreciated!
Here's how to create the Plan that was used:
The replacement SDK is https://github.com/paypal/Checkout-PHP-SDK , which does not include any billing agreement or subscription use cases. For use cases not covered by that SDK , you should use a direct HTTPS integration. This is documented here: https://developer.paypal.com/docs/api/rest-sdks/
The code you are trying to use is for an obsolete SDK for an obsolete API (old version of billing agreements, not compatible with new subscriptions).
Here is the API you should integrate, with no SDK: https://developer.paypal.com/docs/subscriptions/
Turns out an exception is not supposed to be thrown for usual agreement execution. To check whether the setup was paid, check the value of
$agreement->getState() after executing the agreement.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.