How can I accept standalone blik payment using stripe - javascript

How can I accept payment via polish blik on stripe? According to the documentation, Blik payment should be a standalone payment option
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
payment_method_types: ['card', 'blik'],
line_items: [{
price_data: {
currency: 'usd',
// To accept `blik`, all line items must have currency: pln
currency: 'pln',
product_data: {
name: 'T-shirt',
},
unit_amount: 2000,
},
quantity: 1,
}],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
});
when I enter blik in the payment_method_types array I get a typescript error
Type '"blik"' is not assignable to type 'PaymentMethodType'.ts(2322)
Despite that, I tried to create a session as there was an option that silencing TS on one line would do the trick and the checkout session was created, but nothing has happened, no redirect whatsoever, and in the dashboard, I have a session with the status Incomplete and payment method none.
Thanks

Related

Facing Error with Stripe on Create session

I'm building an app with NODEJS and Express while I'm integrate with stripe but facing this type of error
Here is my code:
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
success_url: `${req.protocol}://${req.get('host')}/`,
cancel_url: `${req.protocol}://${req.get('host')}/tour/${tour.slug}`,
customer_email: req.user.email,
client_reference_id: req.params.tourId,
line_items: [
{
name: `${tour.name} Tour`,
description: tour.summary,
images: [`https://www.natours.dev/img/tours/${tour.imageCover}`],
amount: tour.price * 100,
currency: 'usd',
quantity: 1,
},
],
Error: You cannot use line_items.amount, line_items.currency, line_items.name, line_items.de line_items.imagesin this API version. Please useline_items.priceorline_items.price_data`.
Starting from v2022-08-01, the following parameters have been removed from create Checkout Session:
line_items[amount]
line_items[currency]
line_items[name]
line_items[description]
line_items[images]
You can use the price and price_data parameters instead.
Example
const checkout_session = stripe.checkout.sessions.create({
success_url: `${req.protocol}://${req.get('host')}/`,
cancel_url: `${req.protocol}://${req.get('host')}/tour/${tour.slug}`,
customer_email: req.user.email,
client_reference_id: req.params.tourId,
payment_method_types:["card"],
mode:"payment",
line_items:[
{
"price_data": {
"currency" : "usd",
"unit_amount" : tour.price * 100,
"product_data" : {
"name" : `${tour.name} Tour`,
"description" : tour.summary,
"images" : [`https://www.natours.dev/img/tours/${tour.imageCover}`],
}
},
"quantity": 1
}
]}
);

Stripe subscription schedule update - disable prorations

While I try to update subscription, invoice is unnecessary complicated.
await stripe.subscriptionSchedules.update(
subscriptionSchedule.id,
{
end_behavior: 'release',
phases: [
{
start_date: stripeSub.current_period_start,
end_date: stripeSub.current_period_end,
proration_behavior: 'none',
items: [
{
price: stripeSub.plan.id,
plan: stripeSub.plan.id,
quantity: stripeSub.quantity
},
],
},
{
start_date: stripeSub.current_period_end,
proration_behavior: 'none',
items: [
{
price: priceId,
quantity: quantity
},
],
},
],
}
);
I'm updating subscription at the end of current subscription phase.
In stripe subscription change log proration was created for 6.99 and then -6.99.
stripe log
I tried almost everything from stripe docs docs
Can I avoid this to have only one position on invoice with scheduled subscription cost (new subsctiprion is $60) when invoice will be finalized of current phase end?
Current invoice is
6.99
-6.99
60
I want to only be 60

Is it possible to have user input come from a form input in this Stripe example?

Is it possible to modify this Stripe example so as to have the user input an amount in a text box. I am able to alter the amount on the server.js file and i know how to get the form working in the checkout.html but I don't know how to send the value forward when the button is clicked to that server.js can get it.
https://stripe.com/docs/checkout/integration-builder
server.js
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Stubborn Attachments',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
checkout.html
You can, you just have to capture the amount in a form and then POST that data to your server before creating the Checkout Session.
For example:
app.post('/create-checkout-session', async (req, res) => {
const amount = parseInt(req.body.amount, 10) * 100;
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Stubborn Attachments',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: amount,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}/success.html`,
cancel_url: `${YOUR_DOMAIN}/cancel.html`,
});
res.json(session.id);
});
Here's an example of how to do this in Glitch:
https://glitch.com/edit/#!/stripe-checkout-donate
End result looks like this:
https://stripe-checkout-donate.glitch.me/

Google Analytics Data API (GA4) How to use runRealtimeReport function?

I do a call to
await analyticsDataClient.runRealtimeReport({
entity: {
propertyId: propertyId,
},
dateRanges: [
{
startDate: '2020-03-31',
endDate: 'today',
},
],
dimensions: [
{
name: 'city',
},
],
metrics: [
{
name: 'activeUsers',
},
],
});
but this return the following error:
A property in the form 'properties/1234' where '1234' is a GA4 property Id is required
I think it is because my object inside my runRealtimeReport function is wrong but I don't know how to put in.
To create a realtime report, you need to update the request to be similar to
const propertyId = 'YOUR-GA4-PROPERTY-ID';
const [response] = await client.runRealtimeReport({
property: 'properties/' + propertyId,
dimensions: [{ name: 'city', },],
metrics: [{ name: 'activeUsers', },],
});
Please replace the 'YOUR-GA4-PROPERTY-ID' with your numeric property ID. This page describes where to find your GA4 property ID.
Realtime reports do not need dateRanges. Realtime reports are always for the last 30 minutes for your App or Website. There is more information about creating realtime reports on this page.

Adding custom card information to Payment Request

I want to implement payment request api to my website.
Payment request popup lists users saved cards associated with mobile phone and Google&Apple accounts.
I also want to put custom credit cards into that popup because we have already implemented save credit cards feature and it is been working for a while. I couldn't find any support for it reading documentations. Is it possible?
Expected to have a support like
var supportedInstruments = [{
supportedMethods: 'basic-card',
data: {
supportedNetworks: ['visa', 'mastercard'],
supportedTypes: ['credit', 'debit']
},
customCards: [{ //Custom credit cards
number: '000000000000000',
owner: 'John Doe'
}]
}];
var details = {
total: {label: 'Donation', amount: {currency: 'USD', value: '65.00'}},
displayItems: [
{
label: 'Original donation amount',
amount: {currency: 'USD', value: '65.00'}
}
],
shippingOptions: [
{
id: 'standard',
label: 'Standard shipping',
amount: {currency: 'USD', value: '0.00'},
selected: true
}
]
};
var request = new PaymentRequest(supportedInstruments, details);
There's no such feature nor proposal as far as I know, though I have heard similar requests in the past.
One work around would be to implement a merchant specific payment method using the Payment Handler API. This API allows you to provide your own payment method. You can consume it by yourself and allow third parties to do so.

Categories

Resources