paypal / PayPal-PHP-SDK

PHP SDK for PayPal RESTful APIs
https://developer.paypal.com/docs/api/
Other
27 stars 102 forks source link

Questions about Billing agreements #960

Closed JCarlosR closed 7 years ago

JCarlosR commented 7 years ago

General information

Issue description

try { // Execute agreement $agreement->execute($token, $this->apiContext);

$subscription = new Subscription(); // [...] $subscription->paypal_agreement_id = $agreement->getId(); $subscription->save(); } catch (PayPalConnectionException $ex) { echo $ex->getCode(); echo $ex->getData(); die($ex); } catch (Exception $ex) { die($ex); }


It works and the subscription is created in my db. 
However, if I refresh the page, the token can be reused. It still works and none exceptions are thrown.
The `execute` method "accepts" the same token several items.
**I will redirect the user to a different page, but is it a bug?**
___
Question 3:
I have used 2 different sandbox accounts to approve their agreements respectively. 
However, when I enter to the sandbox page, **the credit is still the same, am I doing something wrong?**
___
Question 4:
Considering the question 2, I guess I should use the `BILLING.SUBSCRIPTION.CREATED` event and define a webhook listener to be notified just once after a subscription is created.
But **the sandbox page allows to the sandbox accounts to cancel, suspend and/or reactivate a subscription? Or these events can only occur when my app uses the API to perform these operations?**
___
Question 5:
The Paypal site where the user is redirected shows fields about shipping address.
I want to avoid that, because my app doesn't require that information.
For that, [I have to create a web profile](http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payment-experience/CreateWebProfile.html) and use that with the recurring payments?
___
Question 6:
I have 2 business accounts, which one will receive the payments in the sandbox mode?

Sorry for post a lot of questions, and thank you in advance.
I am implementing the recurring payments for a first time.
xiaoleih41 commented 7 years ago

Q1: I saw it by running the SDK sample code. success=true is a part of URL. Q2: Once the customer approve the agreement, and you execute the EC token and completed the payment, you should not be able re-use the EC token. In my situation I was not able to reproduce another agreement by running the sample code Please provide dBugId . Q3: Please elaborate what you mean by credit and provide examples. Q4: Buyer can cancel the subscription from his account. The rest operation should be done through APIs. Q5: Web experience profile is not supported in Billing agreement at this time. Please see the issue here https://github.com/paypal/PayPal-REST-API-issues/issues/4 Q6 You will need to log in developer.paypal.com dashboard and create a sandbox business account under my account. You can make up an email address whatever you what. You don't have to use real email address.

If Q5 is a critical feature for you, I would encourage you to look in Expresscheckout via Braintree SDK or Braintree Direct PayPal option. instead.

JCarlosR commented 7 years ago

@xiaoleih41 Thank you for your help.

Q1: If I don't get the success=true parameter, it means that the agreement is not being executed? When I was redirected from Paypal to my app, the route only got the token parameter. However the subscriptions were executed (see the next notifications): image

And this capture shows how the user is redirected to my app without the success parameter and the agreement is executed: image

Q2: I have posted an image before (at the issue description). In my Sandbox API Call History, the column Paypal Debug Id is empty :(

Q3: I mean that the balance of the buyers was not updated. But now I have checked it again and the transfer is registered now. When I created the agreement I added 5 minutes to the start date. I did that because I got errors trying to use the exact datetime. There is a way to leave blank the start date and let Paypal to set the proper dateTime immediately after the user aproval? When the user is redirected to my app I want to execute the agreement and know if the billing was procesed successfully at that moment.

Q4: Ok. Then I will allow the users to suspend/reactivate its subscription. Because if they cancel and create a new one, they will be charged twice. But my concern is, if I set a delay to the start date of 5 minutes, when the user approves the agreement, he/she has to wait 1 or 2 minutes in my app for the subscription activation webhook?

Q5: Okay. It is important because the shipping address is useless for the majority of SaaS.

Q6: I have 4 sandbox accounts, 2 of them are business accounts,but I don't know which will be used to receive the payments. Where I can define that?

Unfortunately Braintree is not available for my country (Peru) :/

Thanks again.

xiaoleih41 commented 7 years ago

q1 and q2. I am not sure why it is not in the URL. I would strongly recommend you to use our sample code instead. Q3 and Q4: Use setup_fee instead. It will charge instantly. Q6: The one making the API call should be the one receiving the payments.

JCarlosR commented 7 years ago

Thanks.

xiaoleih41 commented 7 years ago

You define the success=true in the billing plan return URL here You can set the setup_fee the same amount as the the first payment and it should be count as the first payment of the subscription. The APP has to be created from one sandbox account. If you log into developer.paypal.com and click the app, it will tell you which sandbox account it is created under.

JCarlosR commented 7 years ago

I am using the ISO 8601 format for the start_date (when creating a new agreement): image

After create the agreement, I get the paypal approval link and redirect the user to that link. When the user has approved the agreement I get the next object: image Here, the start_date has a different value. Why?

In the Sandbox API Call History I can see the next: image There are two warning icons (cut in half), but I can't see the warning messages. The icons are cut in Chrome but also in Firefox, and I can't see the DebugID that you ask for before.

Thank you again, for your help.

randstraw commented 7 years ago

@JCarlosR this issue will explain the start_date behavior you are seeing https://github.com/paypal/PayPal-Java-SDK/issues/207#issuecomment-255794267. This is also documented https://developer.paypal.com/docs/api/payments.billing-agreements#agreement_create_request

randstraw commented 7 years ago

Closing for now, let us know if you have further questions.

JCarlosR commented 7 years ago

@pp-randy Is it possible to know if the first payment was processed successfully immediately? I mean, after the user approves the agreement?

@xiaoleih41 Told me to use a setup_fee with the same value of the subscription. Is it a not documented trick?

The documentation says "The agreement can take up to 24 hours to activate". Therefore, there is no way to check if the first payment was processed at the moment of the user approval because the operation will be delayed?

Thank you.

randstraw commented 7 years ago

@xiaoleih41 is correct about the setup_fee and it is documented here: payments.billing-plans#definition-merchant_preferences. It can be used with initial_fail_amount_action as well. The setup_fee transaction should be relatively soon and does not follow the 24 hour rule, that is why you can use it for same day billing when its needed.

JCarlosR commented 7 years ago

Is the following correct?

Is that right?

xiaoleih41 commented 7 years ago

@JCarlosR The first payment should start at the start date in both situations following the 24 hours rule. You should get the payment complete webhook for the setup fee payment as well.