Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve session id info #10

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Shippping options optional
Daveed committed Jan 4, 2025
commit 7525b9c0f7b17603254a5b7b0a75946421c1245c
2 changes: 1 addition & 1 deletion src/api/markket/controllers/markket.ts
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ module.exports = createCoreController(modelId, ({ strapi }) => ({

let link = null;
if (body?.action === 'stripe.link') {
link = await createPaymentLinkWithPriceIds(body?.prices || []);
link = await createPaymentLinkWithPriceIds(body?.prices || [], true);
message = 'stripe link created';
}

19 changes: 12 additions & 7 deletions src/api/markket/services/stripe.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const stripeTest = require('stripe')(STRIPE_SECRET_TEST_KEY);
* @param prices
* @returns
*/
export const createPaymentLinkWithPriceIds = async (prices: { id: string, quantity: number }[]) => {
export const createPaymentLinkWithPriceIds = async (prices: { id: string, quantity: number }[], include_shipping?: boolean) => {
const line_items = [];
const custom_price: any = prices.find((price: any) => price.product);
const set_price: any = prices.find((price: any) => price.price);
@@ -44,24 +44,29 @@ export const createPaymentLinkWithPriceIds = async (prices: { id: string, quanti

console.log('create.stripe.payment.link', { line_items });

const paymentLink = await stripeTest.paymentLinks.create({
const stripe_options = {
line_items: line_items.splice(0, 20) || [],
after_completion: {
type: 'redirect',
redirect: {
url: 'https://markket.place/receipt?session_id={CHECKOUT_SESSION_ID}',
},
},
// @TODO: toggle asking for address
shipping_address_collection: {
allowed_countries: ['US'],
},
// @TODO: toggle automatic payouts & charging on behalf of connected account
// on_behalf_of: 'connected_acct_id',
// transfer_data: {
// destination: 'connected_acct_id',
// },
});
};

if (include_shipping) {
// @ts-expect-error
stripe_options.shipping_address_collection = {
allowed_countries: ['US'],
};
}

const paymentLink = await stripeTest.paymentLinks.create(stripe_options);

return paymentLink;
};