PayPal Server SDK: how to approve an order ID - paypal

I was trying to implement paypal api for one of my projects
I am using sandbox environment and server side sdk
In the request i have
{
"intent": "CAPTURE",
"application_context": {
"brand_name": "EXAMPLE INC",
"landing_page": "BILLING",
"shipping_preference": "SET_PROVIDED_ADDRESS",
"user_action": "PAY_NOW"
},
i.e
"intent": "CAPTURE"
"user_action": "PAY_NOW"
I created an order using the api OrdersCreateRequest(). In the response i get the
result.id = "IDVALUE"
result.status = "CREATED"
and also the links
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXX",
"method": "GET",
"rel": "self"
},
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
"method": "GET",
"rel": "approve"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXXXXXXXX",
"method": "PATCH",
"rel": "update"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/XXXXXXXXXXXXXX/capture",
"method": "POST",
"rel": "capture"
}
],
I have tried to open the url
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
"method": "GET",
"rel": "approve"
},
In the browser, it asks for PayPal login, what credentials we have to use as login and password. I have only client_id and client_secret
How to get an approved order id. What should I do now.

The next step is to redirect the payer to that approval_url or use the Order ID with Smart Payment Buttons, which is better than redirecting. Either way the payer will be signing in with their PayPal (sandbox) buyer account or entering their (sandbox) buyer information in a PayPal window or form.
The best approval flow to use is the one at https://developer.paypal.com/demo/checkout/#/pattern/server
Note that it pairs with two routes on your server, one that creates the order and one that captures the order after approval.

How to get the username and the password for the sandbox account.
Navigate to
And we see the email and password which can used to as paypal login credentials while approve the order
So now go to the approve url https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX
and click on login (paypal account) and enter email and password
And after successful login pay here
So now the order gets approved.

Related

I called Paypal subscription API which returns success message but don't see any active subscription in the Paypal dashboard

I am trying to create Paypal subscription through its Rest API using live client and secret.
The API returns success message. The GET subscription API returns the active subscription created, however I don't see any active subscription in my Paypal dashbaord.
Paypal support says the subscription ID does not exist.
Has anyone encountered such issue with Paypal API?
I have attached API JSON response and snapshot herewith.
{
"plans": [
{
"id": "P-4UJ45561KJ704964LMJ2QDZQ",
"product_id": "PROD-4EX86934CR7151923",
"name": "Certified business economist IHK | VO 2022",
"status": "ACTIVE",
"description": "The business economist IHK is divided into the following five subjects with the new examination regulations 2022",
"usage_type": "LICENSED",
"create_time": "2022-05-06T11:09:26Z",
"links": [
{
"href": "https://api.paypal.com/v1/billing/plans/P-4UJ45561KJ704964LMJ2QDZQ",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
]
}
],
"total_items": 1,
"total_pages": 1,
"links": [
{
"href": "https://api.paypal.com/v1/billing/plans?product_id=PROD-4EX86934CR7151923&page_size=2&page=1",
"rel": "self",
"method": "GET",
"encType": "application/json"
}
]
}
First of all, everything in your question shows creating a plan. A plan is not a subscription, it is the cycle details to be able to create a subscription.
Secondly, creating a subscription still will not do anything unless a payer signs in to approve it. For a payer to approve a subscription, use a PayPal button. This is detailed in the Subscriptions Integration Guide.
Note that the createSubscription function can create a subscription for approval itself, by passing it an object with a plan_id (and optionally a plan object to override some part of that plan_id). This is the most simple method.
Alternatively, the subscription can be created via API, at a route on your server which that function will fetch when the button is clicked. Something like:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID_GOES_HERE&vault=true&intent=subscription"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
style: {
label:'subscribe' //Optional text in button
},
createSubscription: function(data, actions) {
return fetch('/path/on/your/server/paypal/subscription/create/', {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
console.log(serverData);
return serverData.id;
});
},
onApprove: function(data, actions) {
/* Optional: At this point, notify your server of the activated subscription...
fetch('/path/on/your/server/paypal/subscription/activated/' + data.subscriptionID , {
method: 'post'
}).then(function(res) {
return res.json();
}).then(function(serverData) {
//
});
*/
//You could additionally subscribe to a webhook for the BILLING.SUBSCRIPTION.ACTIVATED event (just in case), as well as other future subscription events
//Ref: https://developer.paypal.com/api-basics/notifications/webhooks/event-names/#subscriptions
// Show a message to the buyer, or redirect to a success page
alert('You successfully subscribed! ' + data.subscriptionID);
}
}).render('#paypal-button-container');
</script>

Paypal create payment-tokens API return 422 Unprocessable Entity

I am using my paypal sandbox, and I am trying to use v2/vault/payment-tokens API to tokenize a credit card
Url:https://api.sandbox.paypal.com/v2/vault/payment-tokens
Method: POST
RequestBody(fake credit card that sandbox generated):
{
"source": {
"card": {
"number": "40320382525xxxx",
"expiry": "2022-11"
}
}
}
I can make sure that my sandbox have full scopes, my access token is right.
Below is the response:
{
"name": "UNPROCESSABLE_ENTITY",
"message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
"debug_id": "15c1b3e9d8161",
"details": [
{
"issue": "UNKNOWN_BUSINESS_ERROR",
"description": "There was an issue while processing your request."
}
],
"links": [
{
"href": "https://developer.paypal.com/docs/api/vault/v2/#error-UNKNOWN_BUSINESS_ERROR",
"rel": "information_link",
"method": "GET"
}
]
}
Does any one meet the same issue?
Will you have permissions to use /v2/vault/payment-tokens in live mode? This API shouldn't be integrated without guidance from PayPal
Try using a test credit card from https://developers.braintreepayments.com/guides/credit-cards/testing-go-live/node

Can't redirect buyer when he approves the payment

I am using sandbox environment and PayPal Server side Java SDK V2
I have created an order with OrdersCreateRequest() API then i get this classical response including required links
{
"id": "xxxxxxxxxxxxxxxx",
"status": "CREATED",
"links": [
{ xxxxxxxxx },
{
"href": "https://www.sandbox.paypal.com/checkoutnow?token=XXXXXXXXXX",
"rel": "approve",
"method": "GET"
} ,
{ xxxxxxxxx },
{ xxxxxxxxx },
{ xxxxxxxxx },
]
}
In my business use case , I need to redirect the buyer after he goes to approval page , put his credentials and confirm , i want to get token as parameter from redirected link
So i tested this process , the order status become approved but the page doesn't redirect and it just reloads.
I have tried to add this parameter to body of OrdersCreateRequest
"application_context": {
"return_url ": "http://xxx.xx.xxx.x:9000/invoice/10/view"
}
but the page still reloads after approvement.
In this situation I can't know when the buyer has approved the order in my app .

PayPal Future Payment returns 'approval_url'

I'm currently attempting to integrate my app with Future Payments and in the documentation, it mentions:
Unlike the standard REST API docs that demonstrate a one time payment,
a future payment doesn't require you to separately get payment
approval after getting initial user consent. The payment is
pre-approved by the user.
So looking at the example, I should get a response which contains:
"state": "authorized"
"links": [
{
"href": "https://api.paypal.com/v1/payments/authorization/4TD55050SV609544L",
"method": "GET",
"rel": "self"
},
{
"href": "https://api.paypal.com/v1/payments/authorization/4TD55050SV609544L/capture",
"method": "POST",
"rel": "capture"
},
{
"href": "https://api.paypal.com/v1/payments/authorization/4TD55050SV609544L/void",
"method": "POST",
"rel": "void"
},
{
"href": "https://api.paypal.com/v1/payments/authorization/4TD55050SV609544L/reauthorize",
"method": "POST",
"rel": "reauthorize"
},
{
"href": "https://api.paypal.com/v1/payments/payment/PAY-2C433581AX997613HKJFBVLI",
"method": "GET",
"rel": "parent_payment"
}
],
And from what I understand, the transaction, along with the Client Metadata ID and Access Token in the request header, should be automatically processed, without further approval, because the user has already given consent.
So if the transaction intent is 'sale', the success response 'state' would be 'completed' and if the intent is 'authorize', the state would be 'authorized'.
This makes sense, but when testing my app, I'm getting a response with an approval url that I need to redirect the user to and the state is 'created' not 'completed/authorized' ? -
"state": "created"
"create_time": "2016-03-20T00:42:25Z",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-3NA62949E72063722K3W7D4I",
"rel": "self",
"method": "GET"
},
{
"href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-41A06151Y6402822R",
"rel": "approval_url",
"method": "REDIRECT"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-3NA62949E72063722K3W7D4I/execute",
"rel": "execute",
"method": "POST"
}
]
I managed to resolve the issue by removing express_checkout from the scope. If this is enabled, it appears to override future payments so it no longer works and uses the express checkout pay flow instead.

Custom data from paypal JS button into webhook

The JavaScript PayPal button, http://paypal.github.io/JavaScriptButtons/ allows custom data to be sent in the data-custom field.
When using IPN, these data are clearly visible and usable.
However, I don't find any mention of custom data in the webhook documentation; I would expect the "Sale Completed" event to receive something about custom data.
So my question is twofold:
Has anyone managed to get the data and knows what field contains them?
Is there a way to simulate this, given the webhook simulator does not allow any field to be entered?
Webhooks do not support any custom data for simulator. Simulator provides a sample of payload for an event. It does not allow any other data field except URL/EventType. If you want to use the custom data you may use them and don't want to use a live account for testing, you can try it with a sandbox account and go through flow for the Webhook event type for which you want to send custom data.
Also sample for PAYMENT.SALE.COMPLETED for your reference:
{
"id": "WH-2WR32451HC0233532-67976317FL4543714",
"create_time": "2014-10-23T17:23:52Z",
"resource_type": "sale",
"event_type": "PAYMENT.SALE.COMPLETED",
"summary": "A successful sale payment was made for $ 0.48 USD",
"resource": {
"id": "80021663DE681814L",
"create_time": "2014-10-23T17:22:56Z",
"update_time": "2014-10-23T17:23:04Z",
"amount": {
"total": "0.48",
"currency": "USD"
},
"payment_mode": "ECHECK",
"state": "completed",
"protection_eligibility": "ELIGIBLE",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"clearing_time": "2014-10-30T07:00:00Z",
"parent_payment": "PAY-1PA12106FU478450MKRETS4A",
"links": [
{
"href": "https://api.paypal.com/v1/payments/sale/80021663DE681814L",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.paypal.com/v1/payments/sale/80021663DE681814L/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.paypal.com/v1/payments/payment/PAY-1PA12106FU478450MKRETS4A",
"rel": "parent_payment",
"method": "GET"
}
]
},
"links": [
{
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-2WR32451HC0233532-67976317FL4543714/resend",
"rel": "resend",
"method": "POST"
}
]
}
Has anyone managed to get the data and knows what field contains them?
Not Supported.
You may refer for the fields at https://github.com/paypal/JavaScriptButtons#editable-inputs
Is there a way to simulate this, given the webhook simulator does not allow any field to be entered? Not Supported