Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal Adaptive Payment Api pre-populate user data

I am making a website where we are going to host events and would like a user "USER A" to be able to start an event - enter their paypal account info and set a price. Then other users can register for their event and pay USER A directly, with out us having to process their credit card. We would like users that do not have paypal accounts to be able to pay with a credit card.

It looks like Paypal's Adaptive Payment is the best API for us to use to accomplish this. I have it working in the sandbox environment. My problem is this - a user clicks to register for USER A's event , then they enter all their info (name, address, company, ect.) we need to keep this info in our Database so this needs to be done first. Then they will click on a button that says "Pay with Paypal". This creates a paykey and redirects the user to the Paypal login page where the user has 2 options (a. login paypal or b. enter personal info again and credit card information)

I want to know how I can accomplish having all the fields already filled out in the Paypal page , so the user does not have to enter all of their information again. They will be able to delete data in the text boxes if the billing address happens to be different. But all websites I have ever seen to not make the user enter this information twice if they are identical. Now I know this is possible because I have seen other sites do it. I have looked into SetPaymentOptions API , but it is not very clear how that works , and I need user information to be passed even if they are not known to Paypal already.

I tried adding values as suggested in Paypal tutorials like this

<INPUT TYPE="hidden" NAME="first_name" VALUE="John">
<INPUT TYPE="hidden" NAME="last_name" VALUE="Doe">
<INPUT TYPE="hidden" NAME="address1" VALUE="9 Elm Street">

but that didn't work, Here is the raw data from Fiddler from the request :

POST https://svcs.sandbox.paypal.com/AdaptivePayments/Pay HTTP/1.1
Content-Type: text/xml;charset=utf-8
X-PAYPAL-SECURITY-USERID: scotts_XXXXXXXXX_biz_api1.live.com
X-PAYPAL-SECURITY-PASSWORD: 1344XXXXX
X-PAYPAL-SECURITY-SIGNATURE: AOLbPDojAEUdeQJ3wXagJXkxYeJDARg4IXXXXXXXXXXXXXXXXXXX
X-PAYPAL-SERVICE-VERSION: 1.1.0
X-PAYPAL-APPLICATION-ID: APP-80W2844XXXXXXXXX
X-PAYPAL-REQUEST-DATA-FORMAT: XML
X-PAYPAL-RESPONSE-DATA-FORMAT: XML
Host: svcs.sandbox.paypal.com
Content-Length: 810
Expect: 100-continue
Connection: Keep-Alive
like image 569
Scott Selby Avatar asked Nov 14 '22 00:11

Scott Selby


1 Answers

I think for you the problem is not really the login to paypal in a popup, but the paypal registration process to be able to pay with the credit card. There is an api call in the adaptive payment api that allow you to process a registration on the behalf of a user.

You can directly prefil paypal informations on a page using your own design. On submit you create a paypal account using adaptive payment api, and the last step of this process will need you to open a paypal popup which will ask the user to complete his registration by adding a password and credit card information.

After this point you will find back the same payment behavior you have using the simple paypal login.


Please note to even more integrate all your website through paypal you can add preapproval, then the user will only see the paypal website once: when he will accept the preapproval (two steps in a light paypal popup: login > accept).

When the user checkout the first time:

  1. Select between Create an account (using the way I explained above) or Pay with paypal
  2. Create a preapproval key (see the doc on the api, you don't need to know the user paypal login), as returnUrl, specify a url with the local user_id
  3. Open a paypal popup client side using the url returned by the previous step. The user will need to login with his paypal account and then accept the characteristics of your preapproval (limit in time, limit in money)
  4. Paypal will redirect to the returnUrl of step2, it can be a page when you just say "This window will close automaticaly" with a js to close the page
  5. You can now use the preapproval key to make payments on the behalf of the user

When the user checkout after the first time:

  1. Ask for a confirmation "$XX will be taken on your linked paypal account"
  2. Pay using the preapproval key, and it's done!

Hope it will help!

like image 115
Tronix117 Avatar answered Dec 10 '22 21:12

Tronix117