Infinity loop in paypal multi seller - api

I'm currently programming a paypal multi seller checkout with the paypal api v2. In the checkout i always get stuck in a loop after clicking continue. It just says processing and stays like that. I also tried creating another Paypal App but same problem.How can i fix this? I used the following code to generate the order:
const axios = require('axios')
axios
.post('https://api-m.sandbox.paypal.com/v2/checkout/orders', {
"intent":"CAPTURE",
"application_context":{
"return_url":"C:\Users\Felix\Desktop\index.html",
"cancel_url":"C:\Users\Felix\Desktop\index.html"
},
"purchase_units":[
{
"reference_id":"test1",
"payee": {
"email_address": "sb-lgj1x6610750#business.example.com"
},
"amount":{
"currency_code":"EUR",
"value":"100.00"
},
"payment_instruction":{
"disbursement_mode":"INSTANT",
"platform_fees":[
{
"amount":{
"currency_code":"EUR",
"value":"2.00"
}
}
]
}
},
{
"reference_id":"test2",
"payee": {
"email_address": "sb-bong06236339#business.example.com"
},
"amount":{
"currency_code":"EUR",
"value":"7.00"
},
"payment_instruction":{
"disbursement_mode":"INSTANT",
"platform_fees":[
{
"amount":{
"currency_code":"EUR",
"value":"2.00"
}
}
]
}
}
]
},{
headers:{
'Content-Type': "application/json",
'Authorization': "Bearer A21AAJwo7sZjHVhLX3jHjR3HQzE-ojoUzbJUe--WXulQqOzEoV8sF0wNgCUqhOO3N3mDQl5pjnogxOBFmwywr3iXPpj9_VmGA",
'PayPal-Partner-Attribution-Id': 'FLAVORsb-7vgls6637891_MP'
}
})
.then(res => {
console.log(`statusCode: ${res.statusCode}`)
console.log(res.data)
})
.catch(error => {
console.error(error)
})

The return_url must be valid HTTP/S
The receiving (seller) account's email must be confirmed in the sandbox environment, https://www.sandbox.paypal.com/businessprofile/settings/email -- and if they do not have a balance in the transaction's currency (EUR in this example), they must accept a payment in their account's interface to open such a balance, or enable the payment receiving preference to automatically convert received payments to their account's primary balance (often USD, depending on country)

Related

Saleor Integration with Stripe Webhooks

I've been combing through the Saleor docs (following these: https://docs.saleor.io/docs/3.x/developer/available-plugins/stripe and https://docs.saleor.io/docs/3.x/developer/checkout). However, I have found what seems to be an issue (maybe just my ignorance).
This is my rough frontend code, I'll offer a short walkthrough
const onCompletePurchase = async () => {
createPaymentIntentMutation.mutate(undefined, {
onSuccess: () => {
completePaymentMutation.mutate(undefined, {
onSuccess: async ({ data }) => {
console.log(data);
const clientSecret = JSON.parse(data.confirmationData as string).client_secret;
confirmPayment(clientSecret, {
paymentMethodType: "Card",
}).then((result) => {
const { error, paymentIntent } = result;
if (error) {
console.log(error);
} else if (paymentIntent) {
console.log(JSON.stringify(paymentIntent, null, 2));
completePaymentMutation.mutate(undefined, {
onSuccess: () => {
navigation.navigate("CartLanding");
setCheckout({} as Checkout);
},
onError: (error) => {
console.log(error);
},
});
} else {
console.log("Something went wrong");
}
});
},
onError: (error) => {
console.log(error);
},
});
},
onError: (error) => {
console.log(error);
},
});
};
Walkthrough - (Follows these steps https://docs.saleor.io/docs/3.x/developer/available-plugins/stripe)
Creates the payment intent (through saleor)
Completes the payment to get the confirmation information IE: Client Secret (through saleor)
Once gets Client Secret, confirms the payment through stripe
Where issue occurs - Tries to get the order from completing the payment again as detailed in the docs as below
Finalizing a payment
When the customer finalizes a payment, Stripe sends a webhook notification with all details related to this payment. Saleor asynchronously receives the notification and completes checkout process.
On client-side, when stripe.confirmCardPayment doesn't return an error as [described here](https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-submit-payment),
client-side can call checkoutComplete one more time. Saleor confirms that the payment has success status and returns an order object.
However, I believe the issue is this. I call "checkoutComplete" at the same time that saleor receives the webhook notification, resulting in an error with the clients request. If I do for example, setTimeout for 2 seconds, and THEN call checkoutComplete, it works fine, but I believe there is an issue with both of these being called. Am I missing something? or is there a better way to do this WITHOUT using a setTimeout?
Thanks and feel free to ask some questions to figure out the specifics.

How to add selling plan in graphql checkout shopify

I'm new to use Shopify graphql APIs. I create checkout using the below code. My Checkout working fine.
Now I want to add a product with a subscription plan.
I'm getting all plan data and id of the subscription plan added on product data. On the Shopify backend, we use the rechargepayments.com app that is installed in over admin. This is supported by JQuery and an over website subscription working fine.
const query = `
mutation {
checkoutCreate(input: {
lineItems: [{ variantId: "${item.variantId}", quantity: 1, customAttributes: {key: "Shipping Styles", value: "Mixed"} }]
}) {
checkout {
id
webUrl
lineItems(first: 5) {
edges {
node {
title
quantity
}
}
}
}
}
}`
axios({
url: `https://mystore.myshopify.com/api/2021-07/graphql.json`,
method: 'POST',
body: query,
onSuccess: (data) => {
onSuccess({ value: 'Checkout item added' })
},
onFailure: (err) => {
console.log('updateCheckout err ', err);
onFailure({ value: 'fail' })
},
});
Please help me how can I add a selling plan or a subscription using graphql from the mobile application.

how to apple pay through stripe in VJs?

I am trying to follow the guide here ( https://stripe.com/docs/stripe-js/elements/payment-request-button ) to setup Apple Pay for the web and Stripe. The initial steps such as verification of domain and all the pre-setup is done but I am having an issue following the steps for the payment.
The Apple Pay Button is showing up in my Safari browser. When the button is clicked, I fire an event called Paymentmethode() i am facing this error while checking live.Either you do not have a card saved to your Wallet or the current domain (pwafe.devco.pk) is not registered for Apple Pay. Visit https://dashboard.stripe.com/account/apple_pay to register this domain.
main.js:25. and button is hide I get lost after step 3 and not sure what to do. I am posting to my backend and on the backend, creating a payment intent and returning the client_secret
paymentMethod() {
// STEP 1 FROM GUIDE
var stripe = Stripe("pk_test_YxSI6F4QeV0XCofSgabilbTu00ChOmJWJ0", {
apiVersion: "2020-08-27",
stripeAccount: "CONNECTED_STRIPE_ACCOUNT_ID",
});
// STEP 2 FROM GUIDE
var paymentRequest = stripe.paymentRequest({
country: "US",
currency: "usd",
total: {
label: "Demo total",
amount: 1099,
},
requestPayerName: true,
requestPayerEmail: true,
});
// STEP 3 FROM GUIDE
var elements = stripe.elements();
var prButton = elements.create("paymentRequestButton", {
paymentRequest: paymentRequest,
});
// console.log("before api call", paymentRequest);
paymentRequest.canMakePayment().then(function (result) {
// console.log("after api called" + result);
if (result) {
prButton.mount("#payment-request-button");
} else {
//prButton.mount('#payment-request-button');
document.getElementById("payment-request-button").style.display =
"none";
}
});
// STEP 4 FROM GUIDE -- THIS RETURNS A CLIENT SECRET
let clientSecret;
axios
.post("https://pwa.devco.pk/api/Create_PaymentIntent", {})
.then((resp) => {
// Assign this previously defined variable
clientSecret = resp.client_secret;
});
paymentRequest.on("paymentmethod", function (ev) {
// Confirm the PaymentIntent without handling potential next actions (yet).
stripe
.confirmCardPayment(
clientSecret,
{
payment_method: ev.paymentMethod.id,
},
{
handleActions: false,
}
)
.then(function (confirmResult) {
if (confirmResult.error) {
// Report to the browser that the payment failed, prompting it to
// re-show the payment interface, or show an error message and close
// the payment interface.
ev.complete("fail");
} else {
// Report to the browser that the confirmation was successful, prompting
// it to close the browser payment method collection interface.
ev.complete("success");
// Check if the PaymentIntent requires any actions and if so let Stripe.js
// handle the flow. If using an API version older than "2019-02-11" instead
// instead check for: `paymentIntent.status === "requires_source_action"`.
if (confirmResult.paymentIntent.status === "requires_action") {
// Let Stripe.js handle the rest of the payment flow.
stripe.confirmCardPayment(clientSecret).then(function (result) {
if (result.error) {
let data = {
msg: "An error occurred. Please try again.",
};
this.handleShowFlashMsg(data);
// The payment failed -- ask your customer for a new payment method.
} else {
this.handleShowOrderConfirmModal();
// The payment has succeeded.
}
});
} else {
// The payment has succeeded.
}
}
});
});
var paymentRequest = stripe.paymentRequest({
country: "US",
currency: "usd",
total: {
label: "Demo total",
amount: 1099,
},
requestShipping: true,
// `shippingOptions` is optional at this point:
shippingOptions: [
// The first shipping option in this list appears as the default
// option in the browser payment interface.
{
id: "free-shipping",
label: "Free shipping",
detail: "Arrives in 5 to 7 days",
amount: 0,
},
],
});
paymentRequest.on("shippingaddresschange", function (ev) {
if (ev.shippingAddress.country !== "US") {
ev.updateWith({
status: "invalid_shipping_address",
});
} else {
// Perform server-side request to fetch shipping options
fetch("/calculateShipping", {
data: JSON.stringify({
shippingAddress: ev.shippingAddress,
}),
})
.then(function (response) {
return response.json();
})
.then(function (result) {
ev.updateWith({
status: "success",
shippingOptions: result.supportedShippingOptions,
});
});
}
});
var stripe = Stripe("pk_test_YxSI6F4QeV0XCofSgabilbTu00ChOmJWJ0", {
apiVersion: "2020-08-27",
stripeAccount: "CONNECTED_STRIPE_ACCOUNT_ID",
});
},
You should verify domain registration and add card into wallet.tha

Setup Checkout Rest API for Shopify from react mobile app

I am new to shopify, can anyone help me how to setup the checkout API for shopify. I am creating a mobile app with react for a shopify website using API. I tried the one in the shopify docs but it return some error.
post: https://{apikey}:{password}#{hostname}/admin/api/2020-10/checkouts.json
body raw json
{
"checkout": {
"line_items": [
{
"product_id": 5584792125605,
"variant_id": 35877399986341,
"quantity": 1
}
]
}
}
header
X-Shopify-Access-Token : storefront access token
Response
{
"errors": "[API] Invalid API key or access token (unrecognized login or wrong password)"
}
But I've given API key and access token correctly. Is there anything else i should do( I tested this in postman)
Using react native, you have to give the apikey and the password in the Header like this.
getShopifyOrders = () => {
let authorization = base64.encode(
'${Constants.Shopify.key}:${Constants.Shopify.password}'
);
fetch(
'https://${Constants.Shopify.admin_url}/admin/api/2021-04/orders.json',
{
method: "get",
headers: new Headers({
Authorization: 'Basic ${authorization}',
}),
}
)
.then((response) => response.json())
.then((json) => {
console.log(json);
})
.catch((error) => {
console.error(error);
});
};
With Constants.Shopify.key = 'Your_api_key' and Constants.Shopify.password = 'Your_password'
Note : In this code, you have to replace the ' with backsticks ;)

Using Paypal REST api in .net

I am trying to implement PayPal REST API with my .net application. For this I am using the sandbox accounts. By referring the demos/documents below code is written which will first create the order and then will make the payment for the same order.
However, my issue is I am not able to grab the order ID. Though I am getting in res.json() from below code. I need to get the order ID, set it to some variable and use it in the subsequent requests. This below code I have got from the demo link and made some changes as per my requirement.
Also in the OnApprove block I am not getting the data.id.
<div id="paypal-button-container"> </div>
<script>
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
body: JSON.stringify({
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
})
}).then(function (res) {
return res.json();
}).then(function (data) {
return data.id;
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders/' + data.id + '/capture/', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
}).then(function (res) {
return res.json();
}).then(function (details) {
console.log(details);
// Show a success message to the buyer
alert('Transaction completed');
});
}
}).render('#paypal-button-container');
</script>
Also, Can I execute my own APIs from the PayPal buttons ?
Any help on this appreciated !
Your code seems perfect(almost). You just need to keep in mind the scope of the variables here. As the 'data' variable is restricted to the 'then' block, you will need to create a new variable to hold the value of 'data.id' and use it in the onApprove block.
I've added a new variable called 'orderID' in the code below and this seems to be working.
<script>
var orderID; //Declared a variable
// Render the PayPal button into #paypal-button-container
paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
body: JSON.stringify({
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "100.00"
}
}
]
})
}).then(function (res) {
return res.json();
}).then(function (data) {
orderID = data.id; //storing the id in our variable
return data.id;
});
},
// Finalize the transaction
onApprove: function (data, actions) {
//using the id stored in our variable
return fetch('https://api.sandbox.paypal.com/v2/checkout/orders/' + orderID + '/capture/', {
method: 'post',
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer <My Access Token>'
},
}).then(function (res) {
return res.json();
}).then(function (details) {
console.log(details);
// Show a success message to the buyer
alert('Transaction completed');
});
}
}).render('#paypal-button-container');
</script>
The implementation you are doing is ideally used for cases when there is a server side component involved, and the API call to the PayPal servers is done via the server.
If you implementation does not require a server side then I will highly recommend to follow the Smart Payment Buttons implementation - https://developer.paypal.com/docs/checkout/integrate/#