-
Notifications
You must be signed in to change notification settings - Fork 215
feat(payment): PAYMENTS-11577 submit purchase order number as paymentData to createOrder api for purchase order #3251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,19 +1,47 @@ | ||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||
| HostedInstrument, | ||||||||||||||||||||||||||||||||||
| OrderFinalizationNotRequiredError, | ||||||||||||||||||||||||||||||||||
| OrderRequestBody, | ||||||||||||||||||||||||||||||||||
| PaymentIntegrationService, | ||||||||||||||||||||||||||||||||||
| PaymentRequestOptions, | ||||||||||||||||||||||||||||||||||
| PaymentStrategy, | ||||||||||||||||||||||||||||||||||
| } from '@bigcommerce/checkout-sdk/payment-integration-api'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| interface PurchaseOrderPaymentData extends HostedInstrument { | ||||||||||||||||||||||||||||||||||
| purchaseOrderNumber?: string; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function isPurchaseOrderPaymentData(data: unknown): data is PurchaseOrderPaymentData { | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| return typeof data === 'object' && data !== null && 'purchaseOrderNumber' in data; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export default class OfflinePaymentStrategy implements PaymentStrategy { | ||||||||||||||||||||||||||||||||||
| constructor(private _paymentIntegrationService: PaymentIntegrationService) {} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| async execute(payload: OrderRequestBody, options?: PaymentRequestOptions): Promise<void> { | ||||||||||||||||||||||||||||||||||
| const { payment } = payload; | ||||||||||||||||||||||||||||||||||
| let purchaseOrderPaymentData: PurchaseOrderPaymentData | undefined; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||
| payment?.methodId === 'purchaseorder' && | ||||||||||||||||||||||||||||||||||
| isPurchaseOrderPaymentData(payment.paymentData) | ||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||
| purchaseOrderPaymentData = { | ||||||||||||||||||||||||||||||||||
| purchaseOrderNumber: payment.paymentData.purchaseOrderNumber, | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All we need to do here is to throw an error if the payment method is PO and PO data is not provided.
Suggested change
where |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| await this._paymentIntegrationService.submitOrder( | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| ...payload, | ||||||||||||||||||||||||||||||||||
| payment: payload.payment ? { methodId: payload.payment.methodId } : undefined, | ||||||||||||||||||||||||||||||||||
| payment: payment | ||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||
| methodId: payment.methodId, | ||||||||||||||||||||||||||||||||||
| ...(purchaseOrderPaymentData && { | ||||||||||||||||||||||||||||||||||
| paymentData: purchaseOrderPaymentData, | ||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| : undefined, | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+37
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| options, | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think purchase order should not extend
HostedInstrumentas it does not have any of its characteristics. For example, its two fieldsshouldSaveInstrumentandshouldSetAsDefaultInstrumentare not relevant to purchase order. AFAIK, PO is a generated number that could be is different for each order and there will be no need to save it as an instrument.I think with should introduce a new
WithPurchaseOrdertype toOrderPaymentRequestBody.paymentDataand toPaymentInstrumenttype as well (likeWithBankAccountInstrument) where its declaration is simply:This will simplify the
execute()method as in the following comments.