How to integrate paypal - php

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.

Related

PHP - Best way of taking percentage of transaction

I'm building a website in PHP where users place bids on items. Once bidding has ended, a payment needs to be paid from the winning bidder to the listing owner. But, as the website owner, I also want to take a small percentage - say 5%.
So the process would be the winning bidder pays £100 to the listing owner, and I take 5% as that transaction takes place.
What's the best way of doing this?
I've read about PayPal MassPay, but I'm not sure whether it's what I need or not.
I'm in the UK too, not US - if that effects anything.
You can use Stripe Connect to do this if you're in the UK. You would ask your users to connect their Stripe account to your Connect Application first. You would get some data back, especially a publishable_key and an access_token which you would store on your end.
The you would use those this way:
On the front-end along with Stripe.js or Stripe Checkout you need to use the publishable_key you got from the connected user when going through the Connect flow. You should not use your API key.
Once you get a card token you send it to your server where you will create a charge. There, you should not set your API key but you should pass the access_token of the connected user as a second parameter to the Create Charge API. You can see some example code in the documentation showing how to collect fees.
This would automatically deposit the funds in the connected user's Stripe account minus the Stripe fee and the application_fee you chose. The fee would need to be a specific amount and not a percentage but you can calculate this on your end when creating the charge.
Based on your question, the solution would be as following:
Seller adds a listing on your website.
Bidding starts.
Buyer bids and win. E.g. for $10
Buyer pays using PayPal to your website, where money goes to your account (website owner).
You cut 5% of it, ($0.50) and do a Payout to seller's PayPal account of $9.50.
Optionally/Generally, website owners hold the money till the end of the month, and pay the seller the final amount, (if he is selling more than one thing, or he is a big merchant.)
However, the flow should help you setup a website based on your preferences. Many websites like eBay, Free lancing, apply the similar flow.
As a PayPal Employee, I would recommend using PayPal PHP SDK for developing. All the instructions are provided here and here

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.)

IPN feedback for 2 people

I have a page on my site which sends out payments to more than 1 person. I've been testing this using the paypal sandbox account with a few test accounts.
I am also using ipn to get feedback from paypal when payments are complete, pending etc.
My question is, paypal sends me back info via ipn for just 1 of the payments. Why is that? When I check the payment amount in the ipn, it only shows me the payment for 1 of the people who got paid. For example:
If I pay person 1 and 2, where each person gets paid $10 each, so a total of $20. The ipn page only shows me the details for person 1 and says that the payment amount was $10, when the total payment amount is $20.
This is causing me a problem because I need to know that both payments were successful via ipn. At the moment I can only check the payment for 1 person at a time, even though I am paying 2 people at the same time.
How do I get payment for both people?
#Pete answer is a violation of the Paypal User Agreement (unless you have a separate legal entity for both accounts)
9. Restricted Activities
9.1 Restricted Activities. In connection with your use of our website, your Account, or the Services, or in the course of your interactions with PayPal, a User or a third party, you will not:
a. Breach this Agreement (including, without limitation, opening multiple PayPal accounts or breaching the Card Processing Agreement, the Acceptable Use Policy or any other agreement that you have entered into with PayPal (including a Policy));
What you are looking for is PayPal Adaptive Payments. A note about this though: one account - probably you as the application owner - must have a PayPal business account. The others that receive a payment only need a personal account.
PayPal provides an SDK with samples for the Adaptive Payments on Github. Select Adaptive Payments from the menu on the left. There are samples for multiple languages that should be able to get you started.
My hunch is that IPN is tied to the individual account, not the payment, and you have the IPN set up from just one of the accounts. I think what you need to do is configure the IPN on both accounts and then process the response from PayPal two times... once from the IPN notification of the first account, and once from the IPN notification of the second account.

Confirm Express Checkout on PayPal via PHP

This question asked before but didn't got any answer.Maybe things have been changed.
When you click the Express Checkout PayPal button on any webshop, it redirects you to a specific paypal login link, for paying the order.
I have been searching high and low for 3 weeks for a simple paypal php curl script that logs you in from this step, and confirms the payment, but have not been able to find anything.
I found out it is not possible to use the API for this, so its gotta be done by CURL.
I'm asking for this because I run a dropshipping website, and would like to automate certain steps, like placing and paying orders. A working code for this would help not just me, but all looking to automate buying in some form.
Thank's!
You can't log the buyer into PayPal when you redirect them to the site. The buyer has to enter their own account credentials themselves.
If you wanted to bill a buyer without requiring they log into PayPal each time you would need to use billing agreements (reference transactions) through Express Checkout. If you set up a billing agreement with a buyer you can charge a previously successful sale to bill them again for a different amount.
You cannot do what you want with Express Checkout, especially since nobody will ever enter the paypal details on your website (that is the entire point of paypal).
You can use either preapproved payments (buyers preappove payments being taken out of their account up to a certain ceiling), or reference transactions (you reference a new transaction to an older transaction. PayPal will then use the billing details of this earlier transaction to bill the user).
Preapproved payments is part of Adaptive Payments. Documentation is at https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/integration-guide/APIntro/
You can find more details about Reference Transactions at https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECReferenceTxns
Note: Reference Transactions needs to be enabled on your account. This API call is not open to everyone due to the potential for abuse, so you may want to look into whether you're eligible for it before you start working on a full integation with it.
You can find more info here :https://www.paypal-community.com/t5/Merchant-services-Archive/Does-Paypal-have-a-quot-Token-Payments-quot-concept/td-p/325794
Also google "token payments" as that is what you need and most payment gateways usually support them.

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

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?

Categories