-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update modification route and related changes
- Loading branch information
1 parent
9a48203
commit 059b0c8
Showing
8 changed files
with
124 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { | ||
CreatePaymentRequest, | ||
MockPaymentProviderModificationResponse, | ||
MockPaymentProviderResponse | ||
} from '../services/types/payment.type'; | ||
import { Payment } from '@commercetools/platform-sdk'; | ||
|
||
export interface PaymentConnector { | ||
|
||
processPayment: (request: CreatePaymentRequest) => Promise<MockPaymentProviderResponse> | ||
modifyPaymentByPspReference: (pspReference: string, payment: Payment) => Promise<MockPaymentProviderModificationResponse> | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { | ||
CreatePaymentRequest, MockPaymentProviderModificationResponse, | ||
MockPaymentProviderResponse | ||
} from '../services/types/payment.type'; | ||
import { PaymentModificationStatus, PaymentOutcome } from '../dtos/payment.dto'; | ||
import { Payment } from '@commercetools/platform-sdk'; | ||
import {PaymentConnector} from "./PaymentConnector"; | ||
|
||
export class MockPaymentConnector implements PaymentConnector { | ||
|
||
private allowedCreditCards = ['4111111111111111', '5555555555554444', '341925950237632']; | ||
|
||
/** | ||
* @param request | ||
* @returns | ||
*/ | ||
async processPayment(request: CreatePaymentRequest): Promise<MockPaymentProviderResponse> { | ||
const paymentMethod = request.data.paymentMethod; | ||
const isAuthorized = this.isCreditCardAllowed(paymentMethod.cardNumber); | ||
|
||
return { | ||
resultCode: isAuthorized ? PaymentOutcome.AUTHORIZED : PaymentOutcome.REJECTED, | ||
pspReference: uuid(), | ||
paymentMethodType: paymentMethod.type, | ||
}; | ||
} | ||
|
||
async modifyPaymentByPspReference(pspReference: string, payment: Payment): Promise<MockPaymentProviderModificationResponse> { | ||
|
||
return { outcome: PaymentModificationStatus.APPROVED, pspReference: pspReference } | ||
} | ||
|
||
isCreditCardAllowed(cardNumber: string) { | ||
return this.allowedCreditCards.includes(cardNumber); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.