PayPal related programming in PHP with ref to recurring(subscription) payments - php

In normal PayPal flow, for one time payments, first we try to authorize the payment request, and then the next step is to complete the authorisation request.
As per PayPal docs, for recurring(subscription) payments the docs mention that first we have to authorize as usual, after that we have to set up the subscription agreement.
These are my questions-- If you can point me to the relevant APIs (if applicable) that would be great(for points 3 and 4 esp.)
In normal flow, the details of the item(s) being purchased are sent with the authorisation request-- do I do the same for the subscription as well?
Do I send the user to the subscription agreement request after the initial authorisation (i.e. first step--> authorise, second step--> complete authorise) are complete? Or do I do this in place of the second step (ie in place of "Complete Authorise")?
Can I modify an existing subscription agreement- both in terms of changing the amount, as well as changing the description for that subscription agreement?
Can I change only the description for the next recurring amount in an existing subscription?

Related

How to integrate paypal

My website is for people who own bikes, offer them for rent, then clients come and book their bikes for drive.
So here is my problem with paypal.
Client picks bike from list and book it
Client confirms that everything is ok with prices and make payment on Paypal Checkout to my website Paypal business account
Problem starts here:
This amount of $ is not yet taken from client (for 48 hours), owner of bike should confirm it first through his account on my web.
When owner of boat confirms it, then payment executes and take money from clients card or paypal account
After that I pay owner his $ through my business account and that's not a problem. Those 3rd and 4th steps above are.
Is that even possible? If yes, how do i do it?
Thanks!
Yes. It is possible with PayPal.
We are calling it Authorization and Capture. It is a two-step payment model. In this model, Authorization is Step 1, It is happening when the customer is completing his payment.
Capture is Step 2. It is happening when the seller has confirmed the order and he can capture the amount.
For example a client needs to book a bike a bike for 100$. When placing an order, Client will authorize(Normal paypal checkout flow, Nothing different!) 100$. The Owner of the boat get the notification,and If He is having enough boats, He will Capture(This is where amount deduction happens) the amount to proceed further.
Please get more details by following the below link,
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/authcapture/
Please find the example code below
Please follow the link http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/AuthorizePaymentUsingPayPal.html
In the above example, Just note that we are setting Intent "Authorize"
Just remember, In the response you will get "authorization_id".
This is how you have to capture the payment which you authorize from your customer.
http://paypal.github.io/PayPal-PHP-SDK/sample/doc/payments/AuthorizationCapture.html
Note that they are passing "authorization_id" to capture the amount. Once the capture is done, the money will be transferred to Merchant account.

PayPal Billing Agreement with further non regular Reference Transactions

I am implementing PayPal payment to my application.
I am using Laravel Framework and merchant-sdk-php package to handle NVP/SOAP API. I would accually prefer REST API, but i need customers to make Reference Transactions with various amount, in non regular time periods and as far as i know it's possible only with NVP/SOAP API.
The payment flow in shortcut:
1. Payer clicks "connect" button, which is to create billing agreement using "SetExpressCheckout" method. Amount is set to 0 and adding a Billing Agreement field to request. Customer is redirected to PayPal, log in to his account, agreeing to direct debit and finally redirected to my return url.
2. After response is come, return action is fired (the one, which is passed in returnurl field). Next using token from paypal resposne i use CreateBillingAgreement method to get "BillingAgreementID" which i store in database.
3. Using "BillingAgreementID" i make "DoReferenceTransaction" request. No prompt to login is occurring, everything is happening behind the scene. Finally i get response after transaction.
The thinks i want to know are:
1. Is there a way, to get an email address, which consumer used to log in when creating billing agreemenet? I want to show in application which PayPal account (related to mentioned email) is direct debit set to?
2. I want to make some action in databse both after "BillingAgreementID" and "DoReferenceTransaction". Is the response status "Success" and additionally in "DoReferenceTransaction" field "PaymentStatus" set to "Completed" enought to conclude, that transaction is fully completed, and i cant i.e. share some digital goods or should i wait for IPN from this request?
Thanks for all contributions!
Found solution to question 1.
After betting billing agreement id i had to make "GetBillingAgreementCustomerDetails" action. In response i got customer details including email.
Still watching for hint to second question

paypal Preapproval API

we are trying to add a pre-approval paypal process to our website before a user can bid on any of our items for sale. We currently accomplished this using Authorize.net but want to now integrate paypal as well.
I have been doing some research and am trying to find out if paypal even offers such a solution. The main reason for adding this verification is of course to make sure an individual actually has the money to purchase the item, some items can range from $100-$100,000. Does paypal offer a pre approval process for those types of transactions?
https://developer.paypal.com/docs/classic/api/adaptive-payments/Preapproval_API_Operation/
The Preapproval API gives your application permissions to trigger payments on a user's behalf without further approval (no login required to submit payments with a preapproval ID). There is no guarantee funds will be available when you submit this payment. A transaction with a preapproval ID could simply fail like any other transaction.
It sounds like what you're looking is the Authorization and Capture process, which is probably what you're doing with Auth.net, too.
With PayPal you can run Authorizations from credit cards directly (exactly like you do with Auth.net) and you can also do it with Express Checkout, which would be PayPal login payments.

Custom Paypal Cart (Payment ID Number)

We are working on finding a solution for a custom PayPal cart install. I'll try to explain what actions are taking place then point out where we are having issues.
Here is the issue that we are facing:
1.) Users of our site can purchase a subscription
2.) That subscription once paid for activates several actions on the user’s account.
3.) Subscriptions last for Xx amount of time.
4.) Each hour our cron page runs and checks for payment received or not.
5.) After Xx amount of time (the subscription length duration) if the payment is verified to have been received the users account automatically renews. If payment is not verified to have been received then the account we return to normal.
6.) We have it operating correctly in the scenario if the payment is made from one PayPal account for a single user subscription.
7.) However, if a user uses one PayPal account to purchase multiple subscriptions (for this example 10) and cancels X amount (for this example 9) of subscriptions from within their PayPal account, none of the accounts get cancelled from within our site. Say a office manager submits payment from one single PayPal account (because they are in charge of 10 users accounts). Then immediately cancels 9 of the subscriptions from within that sign PayPal account and leaves one active account in our current setup it still thinks a payment was received for all 10 of the users because it’s checking the account rather than individual PayPal subscription for payment. (Tricky to explain)
** What I am are trying to figure out is how to have this action record the Payment ID # that is given by PayPal for each individual subscription when a purchase is completed and when the cron page runs it would pair the user’s (our site user) account to their Payment ID # and take action accordingly. So this way if 9 of the payment ids did not receive a renewal payment those accounts would become inactive and the one payment ID subscription that did receive payment would active properly.
I hope that makes sense and I would really appreciate anyone's help on this. Thanks a ton!
You should be using Instant Payment Notification (IPN) to handle automated updates based on actions that occur on the PayPal account including new profiles, payments, failed payments, canceled profiles, etc.
Any time a transaction occurs on your account (payments, profiles, refunds, disputes, etc.) PayPal's server will POST all of the transaction data to a listener script you have sitting on your server. Within your script you can process that data however you need to, and it happens in real-time.

How to decline a Paypal payment if not from a given residence_country?

We are localizing our website and we want users to be able to pay in USD and EUR, based on their location. Everything is in place, we detect the country based on IP and we choose a currency accordingly. However there is one fraud possibility we haven't tackled yet.
We want prevent our users from paying in USD (the USD price is cheaper) when they are actually in Europe (in case they use a proxy), so I want to use Paypal's residence_country for a double check during or even before payment.
I know I can check the residence_country of the user in the POST data sent to our Paypal IPN notify url. If the country is not the US, I can decline any USD payment by automatically refunding the amount back to the user. Refunding however is not very neat and I noticed that for example Spotify is able to decline a subscription payment before you even pay. So they don't work with refunding. How does this work? How are they able to decline a payment via Paypal before the payment is finished?
It would be nice to be able to pass a country code to Paypal saying "this payment can only be done by a US citizen" but I haven't found such option in the docs here: https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
(Yes we use recurring payments for Payments Standard)
Thanks :)
With PayPal RESTful APIs, you obtain a user’s consent to make Identity API calls on their behalf by redirecting them to the authorization endpoint. Once you obtain the authorization, you can request granular user information from PayPal including user's locale and phone_number.
https://developer.paypal.com/docs/api/#get-user-information
This information should be sufficient to establish, which price level applies.
With PayPal Express Checkout API, when you request the token and user data with
GetExpressCheckoutDetails
ask for their
&COUNTRYCODE=
Then, if it does not match the price they selected, do not charge but use DoVoid (it reverses an order or an authorization that a merchant has made with a customer), reset pricing according to the value of &COUNTRYCODE, and request a new token.
(PayPal will drop the payment authorization after about two days on its own. No need to refund anything if you didn't charge.)
See:
https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECGettingStarted/#id0832BC00JY4
(Be warned: when selling to Europeans, you may be required to register for VAT tax in Europe in a country of your choice if you cross a threshold amount of total revenue per year in any one country of the EU. And then the Europeans wonder why they have to pay more. Excessive red tape drives the costs up.)

Categories