async-stripe icon indicating copy to clipboard operation
async-stripe copied to clipboard

Rework PaymentIntentOffSession API to be more ergonomic

Open wayeast opened this issue 3 years ago • 4 comments

I'm opening this as an issue, even though it's probably closer to the question "How do I make sense of the PaymentIntentOffSession enum?" Apologies if this raises unnecessary alarm.

I wish to use a CreatePaymentIntent object to create a payment intent. From the Stripe docs, the off_session field should be a boolean value; but the CreatePaymentIntent object expects a PaymentIntentOffSession enum. Where did this enum come from, and how should it be used when creating payment intents?

wayeast avatar Jan 15 '22 02:01 wayeast

Yeah, the problem is that the OpenAPI does not exactly follow what Stripe has posted on their website. This particular works like this: You can either specify it as true or false, by using the Exists enum. This is the boolean you're talking about. If you use the second enum, you can specify if the Off session will be used for a one-off or if it will be a recurring charge.

If you are in the United States or Canada, I think you can ignore this field until it becomes a problem. It's off session by default and works fine for me without specifiying.

If you are in Europe, the rules are a little different and more strict, so you may be better off specifying if the type of offsession. This is an opinion, please do testing to confirm anything.

If you want to specify off session, just leave this option at None and it will be OffSession by default. If you want it to be on session, then it looks like:

create_paymen_intent_var.off_session = Some(PaymentIntentOffSession::Exists(true));

This parameter does not guarantee that any charges will not be rejected later by the way, according to Stripe documentation.

erichCompSci avatar Jan 15 '22 18:01 erichCompSci

Thank you for this explanation, @erichCompSci . This is very helpful, especially because it seems to me counterintuitive ("on session" == OffSession::Exists(true)???). Also, my initial reading of the Stripe docs was that off_session could be set to true if and only if confirm were also set to true, and since confirm defaults to false, then these two parameters had to be explicitly set together. From what you're saying, this is not the case. I will try setting neither for actual off-session charges, and to Exists(true) for on-session charges, and see what happens. Thanks again.

wayeast avatar Jan 15 '22 20:01 wayeast

No, no sorry. The documentation about confirm needing to be set to true should still be the case. I'm not sure if this dependency is reflected in the OpenAPI, but I doubt it.

I just forgot about this and didn't mention it. If you want on_session you should set confirm to true and you set OffSession::Exists(true). That is how I think it should work. It's confusing because of the undocumented options and the bad variable name. We do have a mechanism to change that Exists keyword, maybe we should use it to change it to something more intuitive? @arlyon What do you think?

erichCompSci avatar Jan 15 '22 21:01 erichCompSci

Yeah the API is a bit awkward here, mainly because of the openapi it's generated from. I will rename this issue as a feature request to rework the Exists stuff.

arlyon avatar Jan 22 '22 21:01 arlyon