-
-
Notifications
You must be signed in to change notification settings - Fork 35.9k
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
fix: update stripe wallets to use payment intent #54668
base: main
Are you sure you want to change the base?
Conversation
da0270b
to
db66ab6
Compare
shared/config/donation-settings.ts
Outdated
}; | ||
|
||
export const allStripeProductIdsArray = Object.values(stripeProductIds) | ||
.flatMap(env => Object.values(env)) | ||
.flatMap(duration => Object.values(duration)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}; | |
export const allStripeProductIdsArray = Object.values(stripeProductIds) | |
.flatMap(env => Object.values(env)) | |
.flatMap(duration => Object.values(duration)); | |
} as const; | |
export const allStripeProductIdsArray = [ | |
...Object.values(stripeProductIds['live']['month']), | |
...Object.values(stripeProductIds['staging']['month']) | |
]; |
Bit more readable, imo. Also, it's stricter type-wise (it has the literals, not the just string
)
shared/config/donation-settings.ts
Outdated
export const stripeProductIds = { | ||
live: { | ||
month: { | ||
500: 'prod_Cc9bIxB2NvjpLy', | ||
1000: 'prod_BuiSxWk7jGSFlJ', | ||
2000: 'prod_IElpZVK7kOn6Fe', | ||
4000: 'prod_IElq1foW39g3Cx' | ||
} | ||
}, | ||
staging: { | ||
month: { | ||
500: 'prod_GD1GGbJsqQaupl', | ||
1000: 'prod_GD1IzNEXfSCGgy', | ||
2000: 'prod_IEkNp8M03xvsuB', | ||
4000: 'prod_IEkPebxS63mVbs' | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const stripeProductIds = { | |
live: { | |
month: { | |
500: 'prod_Cc9bIxB2NvjpLy', | |
1000: 'prod_BuiSxWk7jGSFlJ', | |
2000: 'prod_IElpZVK7kOn6Fe', | |
4000: 'prod_IElq1foW39g3Cx' | |
} | |
}, | |
staging: { | |
month: { | |
500: 'prod_GD1GGbJsqQaupl', | |
1000: 'prod_GD1IzNEXfSCGgy', | |
2000: 'prod_IEkNp8M03xvsuB', | |
4000: 'prod_IEkPebxS63mVbs' | |
} | |
} | |
}; | |
const stripeProductIds = { | |
live: { | |
month: { | |
500: 'prod_Cc9bIxB2NvjpLy', | |
1000: 'prod_BuiSxWk7jGSFlJ', | |
2000: 'prod_IElpZVK7kOn6Fe', | |
4000: 'prod_IElq1foW39g3Cx' | |
} | |
}, | |
staging: { | |
month: { | |
500: 'prod_GD1GGbJsqQaupl', | |
1000: 'prod_GD1IzNEXfSCGgy', | |
2000: 'prod_IEkNp8M03xvsuB', | |
4000: 'prod_IEkPebxS63mVbs' | |
} | |
} | |
}; |
What is this for? It's not imported anywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmaxed, all of the product ids match what we have on Stripe, and are the correct donation amounts and duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Kris.
if (paymentIntent.status === 'requires_action') { | ||
const { error } = await stripe.confirmCardPayment(clientSecret); | ||
if (error) { | ||
console.log('confirmationError'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log('confirmationError'); |
if (paymentMethod) { | ||
displayError(t('donate.refresh-needed')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear why having a payment method should result in an error being displayed. I would have assumed the opposite, so perhaps this needs a different name or a comment to clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the payment comes after clicking. If it comes before it means something has gone wrong.
I just mapped the use of token to paymentMethod. That error case might have been resolved.
I will give it another look
postPayment, | ||
onDonationStateChange, | ||
handlePaymentButtonLoad | ||
}: WalletsButtonProps) => { | ||
const [token, setToken] = useState<Token | null>(null); | ||
const [paymentMethod, setpaymentMethod] = useState<PaymentMethod | null>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [paymentMethod, setpaymentMethod] = useState<PaymentMethod | null>( | |
const [paymentMethod, setPaymentMethod] = useState<PaymentMethod | null>( |
Nit.
paymentProvider: PaymentProvider.Stripe, | ||
token, | ||
pr.on('paymentmethod', async event => { | ||
setpaymentMethod(event.paymentMethod); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setpaymentMethod(event.paymentMethod); | |
setPaymentMethod(event.paymentMethod); |
Nit.
api-server/src/server/boot/donate.js
Outdated
const subscription = await stripe.subscriptions.retrieve(subscriptionId); | ||
const isSubscriptionActive = subscription.status === 'active'; | ||
const productId = subscription.items.data[0].plan.product; | ||
const isSubscribedInMinutes = isWithinFiveMinutes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why "within"? Surely we want to know that current_period_start
was in the last five minutes, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose for this to check if it has happened recently. 5 minutes is only an arbitrary number.
Do you suggest calling it inLastFiveMinutes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable. To be honest, it was the fact that isWithinFiveMinutes
checked the absolute time difference that got me wondering. That seemed very weird!
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
Checklist:
Update index.md
)main
branch of freeCodeCamp.Closes #XXXXX