@@ -2,6 +2,7 @@ import {expect, sinon} from '@loopback/testlab';
22import { StripeService } from '../../providers/sdk/stripe/stripe.service' ;
33import {
44 CollectionMethod ,
5+ PaymentBehavior ,
56 ProrationBehavior ,
67 RecurringInterval ,
78 TPrice ,
@@ -253,19 +254,52 @@ describe('StripeService - Subscription Management', () => {
253254 expect ( callArg . collection_method ) . to . equal ( CollectionMethod . SEND_INVOICE ) ;
254255 } ) ;
255256
256- it ( 'uses defaultPaymentBehavior from StripeConfig when provided' , async ( ) => {
257- // Create a separate service instance with a custom payment behavior so
258- // callers are not forced to use the SCA-default 'default_incomplete'.
257+ it ( 'uses per-call paymentBehavior when provided on TSubscriptionCreate' , async ( ) => {
258+ stripeStub . subscriptions . create . resolves ( { id : 'sub_custom_003' } ) ;
259+
260+ await service . createSubscription ( {
261+ customerId : 'cus_custom' ,
262+ priceRefId : 'price_abc' ,
263+ collectionMethod : CollectionMethod . CHARGE_AUTOMATICALLY ,
264+ paymentBehavior : PaymentBehavior . ALLOW_INCOMPLETE ,
265+ } ) ;
266+
267+ const callArg = stripeStub . subscriptions . create . firstCall . args [ 0 ] ;
268+ expect ( callArg . payment_behavior ) . to . equal ( 'allow_incomplete' ) ;
269+ } ) ;
270+
271+ it ( 'per-call paymentBehavior takes priority over StripeConfig.defaultPaymentBehavior' , async ( ) => {
272+ // Config says 'error_if_incomplete', but the per-call param overrides it.
273+ const customService = new StripeService ( {
274+ secretKey : 'sk_test_dummy' ,
275+ defaultPaymentBehavior : 'error_if_incomplete' ,
276+ } ) ;
277+ ( customService as unknown as { stripe : StubbedStripe } ) . stripe = stripeStub ;
278+
279+ stripeStub . subscriptions . create . resolves ( { id : 'sub_override_004' } ) ;
280+
281+ await customService . createSubscription ( {
282+ customerId : 'cus_override' ,
283+ priceRefId : 'price_abc' ,
284+ collectionMethod : CollectionMethod . CHARGE_AUTOMATICALLY ,
285+ paymentBehavior : PaymentBehavior . ALLOW_INCOMPLETE ,
286+ } ) ;
287+
288+ const callArg = stripeStub . subscriptions . create . firstCall . args [ 0 ] ;
289+ expect ( callArg . payment_behavior ) . to . equal ( 'allow_incomplete' ) ;
290+ } ) ;
291+
292+ it ( 'falls back to StripeConfig.defaultPaymentBehavior when no per-call value given' , async ( ) => {
259293 const customService = new StripeService ( {
260294 secretKey : 'sk_test_dummy' ,
261295 defaultPaymentBehavior : 'allow_incomplete' ,
262296 } ) ;
263297 ( customService as unknown as { stripe : StubbedStripe } ) . stripe = stripeStub ;
264298
265- stripeStub . subscriptions . create . resolves ( { id : 'sub_custom_003 ' } ) ;
299+ stripeStub . subscriptions . create . resolves ( { id : 'sub_config_005 ' } ) ;
266300
267301 await customService . createSubscription ( {
268- customerId : 'cus_custom ' ,
302+ customerId : 'cus_config ' ,
269303 priceRefId : 'price_abc' ,
270304 collectionMethod : CollectionMethod . CHARGE_AUTOMATICALLY ,
271305 } ) ;
@@ -274,8 +308,8 @@ describe('StripeService - Subscription Management', () => {
274308 expect ( callArg . payment_behavior ) . to . equal ( 'allow_incomplete' ) ;
275309 } ) ;
276310
277- it ( 'falls back to default_incomplete when defaultPaymentBehavior is not configured ' , async ( ) => {
278- stripeStub . subscriptions . create . resolves ( { id : 'sub_default_004 ' } ) ;
311+ it ( 'falls back to default_incomplete when neither per-call nor config is provided ' , async ( ) => {
312+ stripeStub . subscriptions . create . resolves ( { id : 'sub_default_006 ' } ) ;
279313
280314 await service . createSubscription ( {
281315 customerId : 'cus_fallback' ,
0 commit comments