Stripe create Checkout session only with total price - stripe-payments

I'm currently working in a (small) project where we want to create a shop but we aren't selling anything yet.
We are storing our products that we want to sell in our own database.
However I wanted to implement a feature that simulates the payment of an order and I was recommended to use Stripe for it.
However as far as I know I can't create a checkout session without providing a list of products stored in my Stripe account?
So I would need to create all the products in Stripe as well (and have them in my own database too)
Is there no way to just create a checkout session with a total price and when the payment succeeds I can move on?

Yes it’s possible to use Checkout without creating products and prices in Stripe. You need to pass the line_items.price_data object as a parameter when creating the CheckoutSession in order to specify the details of the payment inline (or "ad-hoc").
Here’s an example of how it could look like in node.js:
const session = await stripe.checkout.sessions.create({
line_items: [
{
price_data: {
currency: "usd",
unit_amount: 500,
product_data: {
name: "name of the product",
},
},
quantity: 1,
},
],
mode: "payment",
success_url: "http://example.com/success",
cancel_url: "http://example.com/",
});
You can learn more about Checkout on this documentation page.

Related

Stripe Payment Link creates new customer

We have to use payment links as were coming from a native desktop app on MacOS and Windows, Stripe has no support here.
The native desktop apps do not have a web-view.
Using the following API with url params.
https://stripe.com/docs/payments/payment-links#url-parameters
const paymentLink = await stripe.paymentLinks.create({
line_items: [
{
price: price.id,
quantity: 3,
//
},
],
});
The url on the frontend opens as such (note to "client_reference_id")
final url = link + "?client_reference_id=$customerId&prefilled_email=${stripeCustomer!.email}";
The key url params are added.
The problem is, is that "client_reference_id" is ignored and a new customer is created on the Stripe dashboard, this is no good for making payments as we generate the payment for a specific account created on the database.
Any ideas what I could do here?
We tried checkout session but there is no way to open from a link. :-/
I found the answer to this question. So the generic payment link does not work with a customer id, however you can create a session and attach a customer id to it. The session object will return with a url.
Example:
const session = await stripe.checkout.sessions.create({
line_items: [{ price: price_id, quantity: 1 }],
mode: 'subscription',
success_url: 'https://app.seedscout.com',
cancel_url: 'https://app.seedscout.com',
customer: cus_id,
});
You can find more information in their documentation here.
https://stripe.com/docs/api/checkout/sessions/create
Important to note: Stripe has requirements for the format of customer_reference_id:
client_reference_id can be composed of alphanumeric characters,
dashes, or underscores, and be any value up to 200 characters. Invalid
values are silently dropped and your payment page will continue to
work as expected.
I was tearing my hair out trying to work out why client_reference_id wasn't being passed, and it looks like this was the issue – I was separating two values with a period.

How to make Amazon Pay open in a popup window instead of refreshing?

What I am trying to do: I am trying to integrate Amazon Pay in my React-Express website following this documentation here.
My Problem: Whenever someone clicks on Amazon Pay Checkout Button, it redirects (refreshes the current page) to the Amazon Pay website to complete the payment. The problem in doing so is that, all the states get reset. What I am trying to do is, open it in a popup window.
Note: I have tried Googling, and there were very few information about it, and most of them says its not possible to do, but it is possible. This site here uses Amazon Pay and is built using React, AND this site is from Amazon itself for a demo. Here the Amazon Pay button opens a popup instead of refreshing, but I could not find the source code of this website anywhere.
My Progress:
In my backend Express server, this is what I did,
const payload = {
storeId: AMAZON_STORE_ID,
scopes: ["name", "email", "billingAddress"],
deliverySpecifications: {
specialRestrictions: ["RestrictPOBoxes"],
},
paymentDetails: {
chargeAmount: {
amount: account.price,
currencyCode: 'EUR'
},
},
// popup: true
}
const signature = amazonPayClient.generateButtonSignature(payload)
console.log(`Sign: ${signature}`)
return res.json({ sign: signature, payLoad: JSON.stringify(payload) })
and then in my frontend React,
amazon.Pay.renderButton('#amazon-pay', {
// set checkout environment
merchantId: config.AMAZON_MERCHANT_ID,
publicKeyId: config.AMAZON_PUBLIC_KEY_ID,
ledgerCurrency: 'EUR',
checkoutLanguage: 'en_GB',
productType: 'PayAndShip',
placement: 'Checkout',
buttonColor: 'Gold',
createCheckoutSessionConfig: {
payloadJSON,
signature
},
popup: true
})
Thanks for helping in advance :D
The reason, my Amazon Pay was opening in a new page, and the one in the Amazon Pay Demo website in a popup was because of currency. If, I change my currency from 'EUR' to 'USD', popup appears.
In the demo site, if you change your currency from USD to EUR from top right corner, you will see the changes take place.
So, to fix this issue, I just have to use US Region, and the USD currency

How to set application fees in Stripe while authorize and change amount using Node.js?

In my application, I have to first authorise (Block the payment) the amount from both user. And once they both clicks on confirm once they received the service, I need to perform the charge (Actual cut and transfer payment).
I can do this and works fine but hear I want to get the platform fees but when I add the param of application_fee_amount then it throws an error and says I can only perform this when I do a direct payment transfer.
I think this is very common case which may exist other apps also.
How I'm doing in code...
let obj = {
amount: convertToCents(data.amount),
currency: 'usd',
payment_method_types: ['card'],
capture_method: 'manual',
application_fee_amount: convertToCents(data.amount *0.05), // 5% as a plateform fees...
payment_method: data.payment_method,
customer: data.customer,
confirm: true
}
console.log(obj);
const paymentIntent = await stripe.paymentIntents.create(obj);
Can anyone help me with this?
It doesn't look like you are using a Connect fund flow, like Destination Charges or Direct. ApplicationFees can only be taken on Connect fund flows.
https://stripe.com/docs/connect/charges
Are you using Connect?

Accept custom payment in Stripe Checkout

So I have a simple react frontend connected to stripe checkout, right now I created a product on stripe for 10 dollars and capture it with the API. I would like to implement something where the user can enter a custom amount and send it. Is this possible to do using the stripe checkout only? I do not want to setup a backend or something too complicated. Any ideas will be appreciated thank you :)
lineItems:[
{
price: process.env.REACT_APP_PRODUCT,
quantity: 1,
},
],
mode:"payment",
cancelUrl: window.location.origin,
Yes, it's possible. You can do it like this:
https://jsfiddle.net/captainapollo/atgycd2s/
console.log("I can't put a JSFiddle link without code so here's some code.");

Stripe recurring payments for 3DS source

I want to use Stripe to charge cards recurrently every 30 days with amounts that oscilate.
From the docs I got that if there is a possibility that the card requires 3DS we should use Sources so I switched to sources ;)
From the source object stripe.js retrieves I look at three_d_secure param to decide whether to create a source object that requires 3DS or a normal card charging.
The flow:
With JS I get the source object that has three_d_secure set to either optional or required.
When it's set to optional after I retrieve the source with: source = Stripe::Source.retrieve(source_id) it looks like this:
"status": "chargeable",
"type": "card",
"usage": "reusable",
"card":{"exp_month":12,"exp_year":2032,"brand":"Visa",...
I attach it to a customer and charge it. I guess usage: reusable means that I can charge the card again later...
When three_d_secure=='required' I create a new source calling this:
source = Stripe::Source.create({
amount: amount,
currency: currency,
type: 'three_d_secure',
three_d_secure: {
card: source_id, #src_xcvxcvxcvc
},
redirect: {
return_url: return_url
},
})
I redirect the user to the URL Stripe provides, user enters his 3DS PIN and gets back to my return_url. When Stripe redirects the user back to my return_url I retrieve the source again and get something like this:
"status": "chargeable",
"type": "three_d_secure",
"usage": "single_use",
"three_d_secure": {"card":"src_1B1JzQHopXUl9h9Iwk05JV1z","authenticated":true,"customer":null}
I would expect that after passing the 3DS the source becomes reusable and chargeable until the date of expiry or so :|
My questions are:
1 Why is the 3DS source single_use? Is this like this only in sanbox environment or with the card I am using to test?
2 Can a 3DS protected card be charged again at all?
3 What's the correct approach to attach to customer sources (3DS or normal) that can be charged again and again?
Thank you!
Because it is a source payment token, not a source card token. It expires on a due date or when is consumed. You can use reusable token to create single_use tokens. reusable one represents a card source token
Yes if a 3ds is optional or not_supported, no if required. If required then every payement needs to fulfill a 3ds.
Steps:
Create an src_card_token for a card or use saved one (reusable)
Create an customer object with an src from src_card_token
Create an src_payment_token for a customer using one of his saved cards (as token)
fullfil a 3ds redirect process if required.
create a charge

Resources