@@ -445,35 +445,28 @@ init_(PaymentID, Params, #{timestamp := CreatedAt} = Opts) ->
445445 customer_id = InheritedCustomerID
446446 },
447447 CascadeTokenEvents =
448- case {InheritedCustomerID , PayerParams , VS0 } of
449- {CID , {recurrent , # payproc_RecurrentPayerParams {recurrent_parent = ? recurrent_parent (InvID , PmtID )}}, #{
450- parent_payment : = ParentSt
451- }} when CID =/= undefined ->
452- CubastyTokens = hg_customer_client :get_recurrent_tokens (InvID , PmtID ),
453- ParentToken = make_parent_recurrent_token ( ParentSt ),
454- AllTokens = [ ParentToken | CubastyTokens ],
455- [ ? cascade_tokens_loaded ( AllTokens )] ;
448+ case {InheritedCustomerID , PayerParams } of
449+ {CID , {recurrent , # payproc_RecurrentPayerParams {recurrent_parent = ? recurrent_parent (InvID , PmtID )}}} when
450+ CID =/= undefined
451+ ->
452+ case hg_customer_client :get_recurrent_tokens (InvID , PmtID ) of
453+ [ _ | _ ] = Tokens -> [ ? cascade_tokens_loaded ( Tokens )];
454+ [] -> []
455+ end ;
456456 _ ->
457457 []
458458 end ,
459459 Events = [? payment_started (Payment2 )] ++ CascadeTokenEvents ,
460460 {collapse_changes (Events , undefined , #{}), {Events , hg_machine_action :instant ()}}.
461461
462- make_parent_recurrent_token (ParentSt ) ->
463- # domain_PaymentRoute {provider = ProviderRef , terminal = TerminalRef } = get_route (ParentSt ),
464- RecToken = get_recurrent_token (ParentSt ),
465- # domain_InvoicePayment {created_at = CreatedAt } = get_payment (ParentSt ),
466- # customer_RecurrentToken {
467- id = <<" parent" >>,
468- provider_ref = ProviderRef ,
469- terminal_ref = TerminalRef ,
470- token = RecToken ,
471- created_at = CreatedAt ,
472- status = {active , # customer_RecurrentTokenActive {}}
473- }.
474-
475462maybe_inherit_customer_id (undefined , #{parent_payment := ParentPayment }) ->
476463 (get_payment (ParentPayment ))# domain_InvoicePayment .customer_id ;
464+ maybe_inherit_customer_id (CustomerID , #{parent_payment := ParentPayment }) ->
465+ case (get_payment (ParentPayment ))# domain_InvoicePayment .customer_id of
466+ CustomerID -> CustomerID ;
467+ undefined -> CustomerID ;
468+ _Other -> throw (# payproc_InvalidRecurrentParentPayment {details = <<" Customer ID mismatch with parent" >>})
469+ end ;
477470maybe_inherit_customer_id (CustomerID , _VS ) ->
478471 CustomerID .
479472
@@ -2965,11 +2958,8 @@ construct_payment_resource(
29652958 },
29662959 RecToken =
29672960 case maps :find (Key , Tokens ) of
2968- {ok , T } ->
2969- T ;
2970- error ->
2971- % % Cascade route without pre-existing token — use parent's token
2972- get_recurrent_token (get_payment_state (InvoiceID , PaymentID ))
2961+ {ok , T } -> T ;
2962+ error -> get_recurrent_token (get_payment_state (InvoiceID , PaymentID ))
29732963 end ,
29742964 {recurrent_payment_resource , # proxy_provider_RecurrentPaymentResource {
29752965 payment_tool = PaymentTool ,
0 commit comments