11import {
22 Payment ,
33 PaymentAddTransactionAction ,
4+ PaymentChangeTransactionStateAction ,
45 PaymentDraft ,
56 PaymentSetCustomFieldAction ,
67 PaymentSetCustomTypeAction ,
8+ PaymentTransitionStateAction ,
79 ReferenceTypeId ,
10+ State ,
811 StateReference ,
12+ Transaction ,
913 TransactionDraft ,
1014} from '@commercetools/platform-sdk'
1115import { AbstractResourceRepository } from './abstract'
@@ -111,10 +115,43 @@ export class PaymentRepository extends AbstractResourceRepository {
111115 this . transactionFromTransactionDraft ( transaction , projectKey ) ,
112116 ]
113117 } ,
118+ changeTransactionState : (
119+ _projectKey : string ,
120+ resource : Writable < Payment > ,
121+ { transactionId, state } : PaymentChangeTransactionStateAction
122+ ) => {
123+ const index = resource . transactions . findIndex (
124+ ( e : Transaction ) => e . id === transactionId
125+ )
126+ const updatedTransaction : Transaction = {
127+ ...resource . transactions [ index ] ,
128+ state,
129+ }
130+ resource . transactions [ index ] = updatedTransaction
131+ } ,
132+ transitionState : (
133+ projectKey : string ,
134+ resource : Writable < Payment > ,
135+ { state } : PaymentTransitionStateAction
136+ ) => {
137+ const stateObj = this . _storage . getByResourceIdentifier (
138+ projectKey ,
139+ state
140+ ) as State | null
141+
142+ if ( ! stateObj ) {
143+ throw new Error ( `State ${ state } not found` )
144+ }
145+
146+ resource . paymentStatus . state = {
147+ typeId : 'state' ,
148+ id : stateObj . id ,
149+ obj : stateObj ,
150+ }
151+ } ,
114152 // addInterfaceInteraction: () => {},
115153 // changeAmountPlanned: () => {},
116154 // changeTransactionInteractionId: () => {},
117- // changeTransactionState: () => {},
118155 // changeTransactionTimestamp: () => {},
119156 // setAmountPaid: () => {},
120157 // setAmountRefunded: () => {},
@@ -129,6 +166,5 @@ export class PaymentRepository extends AbstractResourceRepository {
129166 // setMethodInfoName: () => {},
130167 // setStatusInterfaceCode: () => {},
131168 // setStatusInterfaceText: () => {},
132- // transitionState: () => {},
133169 }
134170}
0 commit comments