Get Billing Agreements For Test Accounts - paypal

We are setting up new PayPal integration, and I am having some trouble getting the Billing Agreements. Here is our scenario:
Third party captures payment authorization
Third party sends us the Billing Agreement ID (they call it a Transaction Number)
We do a reference transaction to execute the payment, using that ID (this is done to renew a subscription, typically every 30 days or so)
What I am trying to do is actually write that third part. However, first it must be tested, and I am having trouble getting the billing agreement ID's for my test accounts. I assume that typically that part is handled through a web page that the customer has signed in to with PayPal, so the API knows what purchaser account is being linked. How do I do this programmatically? Or manually? I don't care, because we will never be making this call, I just need the ID's for the test accounts.
Any help is appreciated.

You can do this with Express Checkout. When you call SetExpressCheckout just make sure to include the billing agreement parameters.

Related

How can I obtain a token to charge authorized PayPal accounts as needed?

I have a white labeling Shopify app that bills store owners who install my app whenever orders for my vendor are created in their store. Currently I use Authorize.net as a payment processor. Store owners perform an initial setup whereby they authorize their credit card using a web form I provide. This provides me with a customer profile ID and a customer payment profile ID for the store owner, and I use these two ids to charge their credit card via Authorize.Net for each and every order that is placed through their store for when the order contains one or more of my white label products.
So essentially I have Authorize.Net tokens for each store, and I use those tokens to charge store owners' credit cards as orders come in through their store, and each order has a different charge amount (this is not a recurring payment that is of the same amount each time). Here is some sample code.
I'd like to use PayPal as a backup payment processor and reproduce this same functionality. I'm looking through PayPal's API as well as the Node SDK, and I am not sure how to accomplish the same thing with PayPal. I essentially want to obtain a token tied to the store owner's account which I can use to charge the seller for each order, and each order can have a different charge amount.
Can someone point me in the right direction?
Turns out that what I wanted seems to be Reference Transactions.
For documentation see https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReferenceTxns/.
For an example see this project which uses the paypal-ec2 Node package.
The flow for the example project mentioned above appears to be as follows:
Create Billing Agreement with seller
Visit Express Checkout page
http://localhost:3000/checkout/callback_success is called
Receive token
Redirect to payment URL (which uses token received)
Receive token
Create a billing agreement
(no redirection or confirmation happens)
Receive and store a billing agreement token in database
You now have the ability to process payments in the future for arbitrary transaction amounts using the Billing Agreement ID

paypal reference transactions billing agreement

We require reference transactions via PayPal to bill customers monthly with varying amounts.
e.g. first month is $30, second month may be $35, third month may be $25 etc
So far this seems to be the best approach: https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReferenceTxns/
I am using the PayPal recommended SDK from this page: https://developer.paypal.com/docs/classic/api/nvpsoap-sdks/
and using the ExpressCheckout Method. (paypal/merchant-sdk-php installed via composer)
We have a free PayPal business account.
Testing via Sandbox I am able to:
Get a token (SetExpressCheckout) - category->Digital, billingAgreement, Type=Sale
forward customer to sandbox paypal login
Confirm the payment
redirect back to our system (returnUrl)
Process the payment (GetExpressTocket + doExpressCheckout)
Questions:
Does the PayPal business account require any switch/status/upgrade to enable Reference transactions on the live environment?
How do you setup a $0 billing agreement to invoice an amount later in the month? When passing a 0 amount in step 1 above and error is displayed
Item name, amount and quantity are required if item category is
provided, ErrorCode 10003
This contradicts to documentation https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReferenceTxns/#setting-up-a-billing-agreement-before-payment which states to set the amount to 0...?
UPDATE: Removing the setting $itemDetails->ItemCategory = 'Digital'; solved the $0 amount issue.
Billing ID is not returned even though I've passed the BillingAgreement data
// Billing agreement details
$billingAgreementDetails = new BillingAgreementDetailsType('MerchantInitiatedBillingSingleAgreement');
$billingAgreementDetails->BillingAgreementDescription = $billingAgreementTxt;
$setECReqDetails->BillingAgreementDetails = array($billingAgreementDetails);
I know there are a few questions within the post but I believe they are all related to the scope of 'Reference Transactions' within PayPal.
I'm looking for recommendations on approach and explanations to the contradictions in documentation. (or if I'm doing something wrong then happy to hear it)
To answer your question:
1) Does the PayPal business account require any switch/status/upgrade to enable Reference transactions on the live environment?
If you are receive an error when calling for Reference Transaction, probably that the setting is turned off in your account. You will need to contact PayPal Business Support team to enable it.
2) Billing ID is not returned.
To setup billing agreement, you will need to pass paymentaction=authorization in SetExpressCheckout request. You will not be able to setup billing agreement if you set the paymentaction as sale.

Can i use pre-approval using PayPal website payments pro?

I am making a system in which user permits pre-approval of amount. I've used pre-approval with chained payment. But the problem is that my customer gets redirected to PayPal site and also he/she must have a PayPal account or need to create one. So can i make pre-approval payment using PayPal website payment pro? So my customers will not get redirected to PayPal account. And the process becomes more fast? Note :- I don't want to use authorization and capture method. Thanks.
Edit
One more question :- If i make the website in the UK and the currency in GBP, can I still use the American Paypal account for this?
Auth and Capture is what you're asking for, but then you say you don't want it..?? That's what gives you the functionality you're after, though.
You could do a $0 auth and then run DoReferenceTransaction when you're ready to process the payment as opposed to capturing an actual auth if you want.
Those are your only options when working with Pro, though, and it would give you the same sort of preapproval experience for the buyer.
Here are the steps to accomplish what you're after.
Use DoDirectPayment to run a $0 Authorization (card verification). Users will enter their credit card details directly into a form on your site without any redirection to PayPal (and without any knowledge PayPal is being used at all unless you notify them some way.)
Save the transaction ID that you get form this card verification into your transaction history for the customer in your database. This ID is what will be used to process future payments using that credit card.
When you're ready to process a payment for this customer, pull the ID out of the database and use it with a DoReferenceTransaction request to process any amount you need to.
So the card verification is your preapproval, and then running reference transactions are the same as running Pay requests with a Preapproval key. Both methods accomplish the same thing, but one is with direct credit cards and the other is not.
If you're using PHP you can use this PayPal PHP SDK to make all of the API calls very quick and easy for you. If you're using some other language then there are SDKs available for those as well I'm sure.
Please correct me if i am wrong, #Andrew Angell #Ved Pandya
Auth and Capture or Capture payments later method allows you to do direct payment, but it comes with additional charges, which might not suitable for crowdfunding model as refund/ cancel payment is very frequent
Auth and Capture: You are required to pay $0.30 for each "Card Verification Transactions"
Capture payments later: You are required to pay $0.30 for each "Uncaptured Authorization" that you triggered
https://www.paypal.com/us/webapps/mpp/merchant-fees

Should I remember the payment before getting it authorized?

I get it that Paypal SDK (backed by REST API) has three steps:
Create a payment
payment = Payment({...})
payment.create()
return redirect( redirect_url( payment))
The customer pays and authorizes payment from within Paypal
Redirect to our site where we execute payment, thus transferring money
Should I store the created payments at step 1? I would thus capture all payment attempts, whether successful or not. Or can I create a payment, and not remember it until step 3? That is, record only the successful payments (within their respective Invoices). Is there any reliability or security issue or other harm if I do not store it at step 1?
I suspect not being able to roll back failures.
In Paypal terms, they are of sale intent and are meant for payment of invoices for services rendered. Card data do not touch our servers, I am deferring to Paypal on handling it.
I use paypalrestsdk, Paypal's Python SDK.
Previously, it was tricky to get the PaymentId back when PayPal redirects the page back to your server to authorize you, as there was no way to get PaymentId on 3rd step
However, now, the PaymentId is returned back as a part of the URL as shown here in 3rd step :
http://localhost/Server-SDK/PayPal-PHP-SDK/sample/payments/ExecutePayment.php?success=true&paymentId=PAY-62998961VU1587338KR3AXWQ&token=EC-4YC2489096181311L&PayerID=REABK2UGK7PLW
As you can see it has paymentId which is the Id that you need to store.
So, to answer you dont need to store anything till 3rd step.
Additional Note:
However, if you have some complicated logic/service you want to provide. E.g. send them an email reminder(if you have their emailId), to remind them if they abandoned your card, etc. However, there are many ways to do that besides using these steps.

Parallel preapproved paypal payment?

I have parallel payments working on my test server very nicely, i.e. I can send money to more than 1 person at a time in parallel based on the example parallel.php file I downloaded from the developer paypal site.
I also downloaded the preapproval_flow.php file, but in the code, I can't see a variable/array which allows me to set parallel payment receivers, or even a single receiver for that matter.
Is it not possible to preapprove parallel payments with paypal api's?
If it is possible, how do I do it?
With straight forward parallel payments, I can use the following to set the parallel receivers of a payment:
$receiverEmailArray = array(
'email0',
'email1',
'email2',
'email3',
'email4',
'email5',
'email6',
'email7',
'email8',
'email9'
);
According to cms.paypal.com and x.com, the preappoval_flow has an option called feesPayer, for which the documentation says:
SENDER – Sender pays all fees (for personal, implicit
simple/parallel payments; do not use for chained or unilateral
payments)
The bold bit, tells me that it's possible to do pre-approved parallel payments, but I can't figure out how to sent the receivers...
Also, on x.com, it says:
Developers and merchants can combine;
Parallel and preapproved payments.
The first step in pre-approvals, is on obtaining one from the buyer.
This pre-approval is not tied to any specific seller, but rather to the API caller, and it allows you to make a Pay API call in the future without the buyer having to confirm it.
The pre-approval flow is a separate API call from the Payment flow. In it, you specify the total amount you want to pre-approve, the start and end dates that the pre-approval is valid for, and a few other parameters. (See chapter 8 of the Adaptive Payments dev guide for the full spec: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf )
In this API call, you redirect the buyer to the PayPal site, where he will approve future payments up to the amount you specified. (e.g. if you specified a total amount of $1000, the buyer can make 20 purchases of $50, or 1 big purchase of $1000)
Once the buyer approves this, you have a permission to charge him (In the form of a pre-approval token PA-xxxxxxxxxxxxxx, but at this point no money has changed hands.
Now that you have the token, you can proceed to make the Parallel Payment Pay API call, just like you are doing now, BUT you will specify one additional parameter:
preapprovalKey=<The PA key obtained previously>
(And you also need to make sure that actionType is set to PAY )
As soon as you make this API call, because PayPal sees that you have already obtained permission from the buyer (in the form of the approved PA-key), it will immediately move the money to the receivers specified. There is no need for the buyer to be redirected to approve this payment, since he has already pre approved it. (See the logic here?)
So to recap:
Make call to Pre-Approval API, to obtain permission to charge from the buyer
Make call to Pay API (that includes the PA key from step 1) to execute on the permission given