Paypal Express checkout - not getting billing agreement ID - paypal

I'm trying to test reference transaction with Paypal Expresscheckout billing agreement id. But I don't get the BAID at all.
Here are the calls I'm making:
STEP 1: setExpresschecout call:
Request
Endpoint URL: https://api-3t.sandbox.paypal.com/nvp
HTTP method: POST
------------------------------------------------------------
POST data:
USER=insert_merchant_user_name_here
&PWD=insert_merchant_password_here
&SIGNATURE=insert_merchant_signature_value_here
&METHOD=SetExpressCheckout
&VERSION=93
&PAYMENTACTION=SALE # type of payment
&AMT=19.95 # amount of transaction
&CURRENCYCODE=USD # currency of transaction
&RETURNURL=<return_url> # URL of your payment confirmation page
&CANCELURL= <cancel_url> # URL redirect if customer cancels payment
&L_BILLINGTYPE0=MerchantInitiatedBilling
-------------------
Response
----------------------
token=EC-7NH28597U8423791A
-----------------------
It's reirecting me to Paypal for login and after clicking on 'Agree and Pay' button, redirecting me back to my site with token and payerID. As I don't need to store the customer details, I'm skipping GetExpresschecout call and directly calling doExpressCheckoutPayment with token and PayedID.
STEP2 : doExpresschecoutpayment
USER=insert_merchant_user_name_here
&PWD=insert_merchant_password_here
&SIGNATURE=insert_merchant_signature_value_here
&METHOD=DoExpressCheckoutPayment
&VERSION=93
&PAYMENTACTION=SALE # type of payment
&AMT=19.95 # amount of transaction
&CURRENCYCODE=USD # currency of transaction
&TOKEN=token_value
&PAYERID=payer_id_received
Here is the response. But it doesn't have the BILLING agreement id.
{"map":{"PAYMENTINFO_0_REASONCODE":"None","PAYMENTINFO_0_TAXAMT":"0.00","PAYMENTINFO_0_SECUREMERCHANTACCOUNTID":"KLQ6JKXB6DPZ6","TRANSACTIONID":"96C270379E2177052","PAYMENTINFO_0_TRANSACTIONTYPE":"expresscheckout","AMT":"11.20","PAYMENTINFO_0_FEEAMT":"0.62","CORRELATIONID":"fa14c423b7813","SUCCESSPAGEREDIRECTREQUESTED":"false","TAXAMT":"0.00","PAYMENTINFO_0_CURRENCYCODE":"USD","PAYMENTINFO_0_TRANSACTIONID":"96C270379E2177052","PENDINGREASON":"None","PAYMENTINFO_0_PAYMENTTYPE":"instant","VERSION":"98.0","PAYMENTINFO_0_PENDINGREASON":"None","FEEAMT":"0.62","ACK":"Success","TRANSACTIONTYPE":"expresscheckout","TOKEN":"EC-7NH28597U8423791A","PAYMENTINFO_0_ERRORCODE":"0","BUILD":"5956203","PAYMENTINFO_0_ORDERTIME":"2013-05-12T12:55:48Z","PAYMENTINFO_0_PROTECTIONELIGIBILITY":"Eligible","INSURANCEOPTIONSELECTED":"false","ORDERTIME":"2013-05-12T12:55:48Z","PAYMENTSTATUS":"Completed","PAYMENTINFO_0_AMT":"11.20","PAYMENTINFO_0_PAYMENTSTATUS":"Completed","REASONCODE":"None","PAYMENTTYPE":"instant","PAYMENTINFO_0_ACK":"Success","PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE":"ItemNotReceivedEligible,UnauthorizedPaymentEligible","SHIPPINGOPTIONISDEFAULT":"false","TIMESTAMP":"2013-05-12T12:55:48Z","PROTECTIONELIGIBILITY":"Eligible","CURRENCYCODE":"USD"}}
FYI..paymentaction is set to SALE as I need to capture the payment.
Any suggestions on what went wrong?
Thanks,
Punya

You will need to run CreateBillingAgreement API to get BAID.
This should be done after you get EC token from SetExpressCheckout API.
P.S Reference Transaction should be enabled on your account.

You will need to use "GetExpressCheckout" to see if they accepted the billing agreement or not.
You will also need to contact PayPal and specifically request that Billing Agreements and subsequently Reference Transactions are turned on for your merchant account.

Related

How to excute in Rest API if the return_url request lost after user has paid

I am integrating Express Checkout payments in my web by using REST API, and setting the payment intent to sale for making an immediate payment.
Here follows my steps:
1. create a direct payment by /v1/payments/payment, and set redirect_urls;
2. redirect the buyer using the approval_url in the response of step1;
3. when the buyer approves the payment, the full page will be redicrected to the url that I've been provided in redirect_urls, and then I will execute the payment to complete the payment.
My question here:
what if the redirect_url lost in my step3? The buyer paid but I wouldn't be notified. I would not receive the PAYMENT.SALE.COMPLETED webhook neither because I didn't execute the payment.

Paypal Subscription Details

Can you help me. I need to know if PayPal has an API call to get subscription details like the enddate of the subscription?
I do the request to PayPal and get the response,
SUCCESS
transaction_subject=Name20
payment_date=10%3A42%3A50+Mar+28%2C+2014+PDT
txn_type=subscr_payment
subscr_id=I-MWMMATTBSY2M
last_name=jls
....
but I need details from suscription as enddate.
Sounds like you're using Standard Subscriptions and the "response" you're referring to would be an Instant Payment Notification (IPN)..??
Unfortunately, the standard subscriptions system doesn't have any API's to access details directly. You could switch to Express Checkout and the Recurring Payments API, though, and this would give you access to API's to obtain details and manage the profiles programatically.
If you're working with PHP you can setup Express Checkout and Recurring Payments very easily using my class library for PayPal.
The flow you'll be setting up would be as follows...
1) Call SetExpressCheckout to obtain a token and redirect the user to PayPal. The SEC request will also include a ReturnURL which is where PayPal sends the user after they've signed in and agreed to continue. You also need to make sure to include the Billing Agreement parameters in your SEC request so that the token you get will be compatible with recurring payments.
2) The user ends up back at your ReturnURL, and this is where you'll call GetExpressCheckoutDetails to obtain details about the buyer that the system now knows since they've signed in. This gives you info like the payer's name, email, address, etc. It also gives you the Payer ID you'll need for the final request.
3) Right after obtaining the details via GECD you'll call CreateRecurringPaymentsProfile to finalize the subscription profile creation.

Getting Transaction details on Enhanced recurring payment service

My application comprises of a subscription service. I have implemented the section using Paypal standard. What i did to make a recurring a recurring profile is to do a SetExpressChekout call initially and then with the response token, i redirect the browser to Paypal and there he could login to Paypal and accept the terms and condition for the payment and then the browser will be redirect back to the url i specified as the return url with token as the query string. With this token i make a doexpresscheckout api call and then convert the transaction to a recurring profile, the profile id, transaction id will be stored in database for refund transaction, recurring profile cancellation etc. And also this profile id is needed in IPN which logs further recurring payment transaction in my database successfully. Everything works fine in this environment.
Now my customer needs to have credit card transaction along with Paypal transaction. For that he has sign up for enhanced recurring payment. I have created a subscription button with item name amount currency success and cancel url and generated the html for the hosted buton and pasted it in my form. On clicking the button the browser gets redirected to paypal and i could pay with both paypal and credit card. Once the payment is completed and i am redirecting back to success url. but my success url query sting only contains auth parameter. I am getting no idea on how to use this parameter to get the details of the recurring payment like profile id and transaction id to log to my database. If it is received only via IPN how could i know whether the profile id belongs to which user.
Thanks and regards
With Website Payments Standard you can set the custom parameter to contain specific data about the user.
For example;
<input type="hidden" name="custom" value="hashedStringofUserID">
This data will subsequently be returned in the IPN POST payload's custom key.

Paypal shipment details

I am using PayPal Adaptive payments (chained payments).
If I set:
1. CREATE payment
2. In the SetPaymentOptions -> Requires shipping address selection = true
3. When I redirect user for the https://www.sandbox.paypal.com/webscr&cmd=_ap-payment&paykey=[PA KEY] user after authentication is not shown any prompt for shipping address
why?
Accordingly to the
https://www.x.com/developers/paypal/documentation-tools/api/pay-api-operation
when using CREATE I should do: CREATE – Use this option to set up the payment instructions with SetPaymentOptions and then execute the payment at a later time with the ExecutePayment.
But as soon as I try to run ExecutePayment I get the following information:
This payment request must be authorized by the sender
How can I set additional payment options then?
The ExecutePayment call would only be used if you're utilizing delayed chained payments. Otherwise, the payment still happens as soon as the buyer logs in and approves it, so there is no need for ExecutePayment. Calling it at that point results in the error you're getting, that the paykey was already used.
Did the sender actually authorize the payment?
The flow should be like:
Call Pay API operation with actionType as CREATE
If paymentExecStatus=CREATED and ack=SUCCESS, obtain payKey (here, keep detailLevel=ReturnAll in RequestEnvelope field of your Pay API request)
Redirect user to Paypal https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=YOUR_PAYKEY_ABOVE
If user approves payment, you will be redirected to your returnURL sent as a part of Pay API request
Verify approval status using PaymentDetails API operation
Later you can execute the payment thus setup in step 4 using ExecutePayment API operation. Send the same payKey you obtained in step 2.
You have got error code 550001 since the user approval seems to be not yet done successfully. It may be due to:
The application did not redirect user/sender to Paypal for authorization
OR
The user did not enter correct login details
OR
There were not sufficient funds available
etc.

Page Protection

I've had a difficult time working with PayPal express checkout... Basically I'm looking to protect a PAGE, not a download or anything. The user pays and they can access that page one time. And have to pay each time they want to access the page.
Does anyone have a simple PHP solution to protect my page until the person pays through PayPal? Or even a pre-written example of the PayPal code for Digital Goods for Express Checkout?
Thanks in advance.
PayPal doesn't have much to do with this -- it's all about the logic you place on your 'return page' (the page the buyer returns to after they have completed payment).
For a simple Express Checkout integration you would:
1. Call the SetExpressCheckout API
2. Supply the AMT, RETURNURL and CANCELURL
3. Retrieve the token as returned in the SetExpressCheckout response.
4. Redirect the buyer to https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-xxxtoken-herexxx&useraction=commit
5. When the buyer agrees to the payment and is returned back to your RETURNURL, call the GetExpressCheckoutDetails API and supply the token to retrieve the PayerID (alternatively; the token is also appended in the GET array for your RETURNURL)
6. Call DoExpressCheckoutPayment to finalize the payment.
7. Now that the payment is complete, do whatever logic you have to to ensure the transaction is completed and provide the buyer access to the content you wish him/her to see (could be the RETURNURL page itself, or a completely different page).
Sample (NVP) API calls would look similar to the following:
SetExpressCheckout Request
METHOD=SetExpressCheckout&USER=yourAPIuser&PWD=yourAPIpwd&SIGNATURE=yourAPIsig&VERSION=78.0&AMT=0.01&RETURNURL=http://www.your-return-url.com/&CANCELURL=http://www.cancelurl.com/
SetExpressCheckout Response
......
Ack=Success
TOKEN=EC-12345678
.......
GetExpressCheckoutDetails Request
METHOD=SetExpressCheckout&USER=yourAPIuser&PWD=yourAPIpwd&SIGNATURE=yourAPIsig&VERSION=78.0&TOKEN=EC-12345678
GetExpressCheckoutDetails Response
.....
Ack=Success
PAYERID=ABCDEFGH
......
DoExpressCheckoutPayment Request
METHOD=SetExpressCheckout&USER=yourAPIuser&PWD=yourAPIpwd&SIGNATURE=yourAPIsig&VERSION=78.0&AMT=0.01&PAYERID=ABCEDFGH&TOKEN=EC-12345678
DoExpressCheckoutPayment Response
....
Ack=Success
PAYMENTSTATUS=Completed
....
See also
SetExpressCheckout: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_SetExpressCheckout
GetExpressCheckoutDetails: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails
DoExpressCheckoutPayment: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_DoExpressCheckoutPayment
As well as https://www.x.com/ > API Reference.
Note: I'm using "useraction=commit" in the redirect URL to PayPal because that will change the 'Continue' button on the PayPal 'Review Your Payment' to a 'Pay now' button. Thus implying the buyer will be immediately charged as soon as he clicks on that button. It's just handy.