How to allow customers pay with different currencies in PayPal? - paypal

I am trying to understand how to integrate PayPal Express Checkout in Java, now at first I was successful to apply the scenario where customer approve payment by sending the below request and then getting the approve HATEOAS ref link:
curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
"intent": "AUTHORIZE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
}'
After that I capture the request where it appears that both customer and seller transactions are okay. But when trying to pay with another currency_code like for example MAD I get the below error:
{"name":"UNPROCESSABLE_ENTITY","details":[{"location":"body","issue":"CURRENCY_NOT_SUPPORTED","description":"Currency code is not currently supported. Please refer https://developer.paypal.com/docs/integration/direct/rest/currency-codes/ for list of supported currency codes."}],"message":"The requested action could not be performed, semantically incorrect, or failed business validation.","debug_id":"","links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-CURRENCY_NOT_SUPPORTED","rel":"information_link","method":"GET"}]}
Is there any workaround to force multiple currencies on checkout? Or how to implement currency conversion?

MAD is not a PayPal-supported currency
Here is the complete list: https://developer.paypal.com/docs/api/reference/currency-codes/
If the buyer has a funding source in a different local currency (such as a credit card with MAD) a conversion will be shown to them in the checkout. But your transaction must be denominated in one of the PayPal supported currencies, and you will receive that currency.
The best approval flow is not link or redirect-based, but rather keeping your site loaded in the background and opening an in-context window. Here is the front-end UI for that: https://developer.paypal.com/demo/checkout/#/pattern/server
It does require the currency to be known at page load time (or a later async load).
You'll need two corresponding routes on your server, one for 'Set Up Transaction' like in your question, and one for 'Capture Transaction'. There is a guide for them here: https://developer.paypal.com/docs/checkout/reference/server-integration/

Related

Why should `amount` be sent to BrainTree PayPal Configuration when using the `Drop-In`?

I am wondering why we must send the amount of money during requesting the nonce when we using BrainTree Drop-In with PayPal payment method. I found that this value is not being used at all.
The only value that is being used to determine the amount of money to take is that value I send when using the nonce I received (and it could be anything different than what I send as amount).
Here is a simple code:
braintree.dropin.create({
authorization: token,
container: '#checkout-container',
paypal: {
flow: 'checkout',
amount: '1000000000', // This value is not being used!!!
currency: 'EUR'
}
}, callback);
Does anyone know why we should send this value if it is not being used?
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
In using the PayPal Checkout workflow - flow: "checkout" - you're authorizing PayPal to charge that amount to the customer. The amount is required and will return an error if not included.
amount is not required for the PayPal Vault workflow - flow: "vault" - because you are creating a billing agreement with the customer to charge them any amount in the future.
For more info on the two different PayPal workflows, check out Braintree's documentation.

How can a server know a payment was truly made via PayPal client side REST API?

I was looking the PayPal interactive integration demo link.
At some point after the user complete the payment flow, the client reach the code:
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Make a call to the REST api to execute the payment
return actions.payment.execute().then(function() {
window.alert('Payment Complete!');
});
}
In a real scenario, instead of an alert, I would probably like to send the server a instruction to ship a product or update the user plan. And it would probably be done via an HTTP POST request.
How can the server know that indeed a payment was made and it was not a result of an hacker sending an http post request manually?
After actions.payment.execute() you can call your server and have it make a GET call to verify the payment has been completed: https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-payments-api/show-payment-details/
Your idea is correct, the server cannot know if the payment was really made. This client API is intended for things like donations, where no request to any servers is necessary. The client callback can then be used to display a "thank you" note or similar to the user.
For most cases (like online shops etc.) you will want to use the server API. That way, the PayPal server will send a request to your server, so you can validate that it really is a genuine payment confirmation.
1) generate a unique reference server side in your database that includes the payment details. For example:
My paypal references table
| Amount: $1.00 | Reference: ECHI5786786 |
2) Pass the payment reference in your transaction object before excuting the payment.
"transactions": [
{
"amount": {
"total": "1.99",
"currency": "USD"
},
"soft_descriptor": "ECHI5786786" //this is your unique reference
]
3) In your PayPal app configuration, on the developers site, set a webhook to your server for "payment sale completed". PayPal will call your url with the transaction details including the unique reference. Record the details in your database. For example
My paypal confirmed completed payments table
| Amount paid: $1.00 | Reference: ECHI5786786 |
4) When PayPal confirms the payment is complete client side, send a request to your server to confirm payment details
// Make a call to the REST api to execute the payment
return actions.payment.execute().then(function() {
//ajax to your server here with "soft_descriptor"
//if ajax success, then all good
});
Serverside confirmation
Confirm that the reference is in both tables and that the amount matches

How can I query PayPal for a list of transactions?

I've been looking through the PayPal developer documentation, but things are a bit confusing. I've found the Express Checkout - NVP/SOAP documentation, but it is listed as deprecated. I don't want to implement something that will go away soon or is outdated.
What API call should I use to retrieve a list of transactions/payments from PayPal?
Use PayPal rest API Lists payments: It will list all payments, that were created by the create payment call using PayPal rest API and that are in any state.
The list shows the all payments that are made to the merchant who makes the call.
Sample CURL Request:
curl -v -X GET https://api.sandbox.paypal.com/v1/payments/payment
count=10&start_index=0&sort_by=update_time&sort_order=asc \
-H "Content-Type:application/json" \
-H "Authorization: Bearer Access-Token"
For more info, check PayPal rest API payment documentation

I am not able to trigger Paypal REST API webhook events

I'm trying to implement the Paypal REST API for a client and I'm at the point where I need to test the webhook system. I can not get the API to generate an event; a successful payment should generate one, I've also tried using the REST API to issue refunds, and I've tried issuing refunds from the developer sandbox. None of those activities have generated an event for me.
For example, if I execute the command:
curl -v -X GET -H 'Authorization: Bearer VALID_BEARER_TOKEN' 'https://api.sandbox.paypal.com/v1/notifications/webhooks-events'
I get this:
{"events":[],"count":0}
Even after a dozen or so successful payments and maybe a half-dozen refunds, in both sandbox and live, I see "count": 0. The sandbox merchant center and transaction detail both are aware of the correct state of each transaction, and if I query the /v1/payments/payment/{id} resource, I see the correct state for that {id}.
Operationally, I have everything set up correctly:
the webhook uri is registered correctly in the app details, with subscriptions to all event types
the endpoint has a valid SSL Certificate
the endpoint has no firewall or other security that would prevent a successful SSL connection (I've tested this thoroughly)
I have application logging ratcheted up to the finest detail, with no results. I have tcpdump listening on the webhook target machine just to see if any handshake is attempted, also with no results. I've even tried the old "delete and recreate" trick with the app, which didn't help. I've also registered a new PayPal merchant account and encountered the same problem.
I do see IPN traffic for one of the accounts that had a default IPN handler enabled. I would prefer to use the webhooks if at all possible, the reason my client wants to do this in the first place is to get away from IPN.
Am I missing a setting somewhere? Is there some magic undocumented flag? Or is webhook support too new and I shouldn't rely on it and just stop wasting my time and go back to IPN?
There's nothing wrong on your side. If you do sale, paypal webhooks only support echeck case for now. PayPal is adding webhooks support covering other funding sources for sale payment, estimated release is in next Jan.
To update this thread, PayPal has added webhooks support for other funding sources for sale payment.
https://developer.paypal.com/docs/integration/direct/rest-webhooks-overview/

Programmatically pay a Dwolla account with API?

I am working on an application where I would need to send funds via the API, if possible, programmatically. Is this possible with Dwolla?
Im not the developer so I'll explain best I can. I think it would be similar to what's possible with Paypal's adaptive payments API. Basically, as the owner of a Dwolla account, I need to send money to another Dwolla account using the application. The receiver's Dwolla account#, payment amount, source, and my pin are all stored/generated from the application so that manually entering this information isn't necessary.
Our REST API's Transactions / Send method is exactly what you're looking for. It allows you to send money on behalf of a Dwolla user programmatically.
The Send endpoint takes all the parameters you mentioned. A request can be as simple as:
POST https://www.dwolla.com/oauth/rest/transactions/send
Content-Type: application/json
{
"oauth_token": "Hyq7SiSHZ90i6seupTmhx8PPPykfuP94T5bSYW1XI9qvab7YQN",
"pin": "1278",
"destinationId": "812-713-9234",
"amount": "309.21"
}
Note that this endpoint requires you to supply an OAuth token. Read about how they're obtained here.