-
Notifications
You must be signed in to change notification settings - Fork 0
feature(payment-provider): Added payment provider for QR code. Remove… #412
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9f72540
feature(payment-provider): Added payment provider for QR code. Remove…
ztomas-codes 55d6d9b
feature(provider): CR fixes
ztomas-codes d736775
feature(payment-qr): gate QR payment module
ztomas-codes 4defaf2
fix(provider): CR fixes
ztomas-codes 072f055
fix(provider): CR fixes
ztomas-codes 089d4df
fix(provider): CR fixes
ztomas-codes 24457a0
fix(provider): CR fixes
ztomas-codes bfb4a3d
fix(receipt): correct invoice item quantities
ztomas-codes 57f138e
fix(receipt): preserve discounted line totals
ztomas-codes d6660e1
fix(provider): simplify QR feature flag
ztomas-codes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
apps/medusa-be/src/modules/payment-qr/__tests__/manual-provider.unit.spec.ts
This file contains hidden or 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,102 @@ | ||
| import { describe, expect, it, vi } from "vitest" | ||
| import { QR_PAYMENT_MODULE } from "../constants" | ||
| import { QrManualPaymentProvider } from "../services/manual" | ||
|
|
||
| const PNG_DATA_URL_PATTERN = /^data:image\/png;base64,/ | ||
|
|
||
| describe("QrManualPaymentProvider", () => { | ||
| it("generates SPAYD and QR image data for a payment session", async () => { | ||
| const getIban = vi.fn().mockResolvedValue("CZ65 0800 0000 1920 0014 5399") | ||
| const provider = new QrManualPaymentProvider({ | ||
| [QR_PAYMENT_MODULE]: { getIban }, | ||
| }) | ||
|
|
||
| const result = await provider.initiatePayment({ | ||
| amount: 1234.5, | ||
| currency_code: "czk", | ||
| context: { | ||
| idempotency_key: "1234567890", | ||
| }, | ||
| }) | ||
|
|
||
| expect(result.id).toBe("1234567890") | ||
| expect(result.status).toBe("pending") | ||
| expect(result.data?.payment_qr_spayd).toContain( | ||
| "ACC:CZ6508000000192000145399" | ||
| ) | ||
| expect(result.data?.payment_qr_spayd).toContain("AM:1234.50") | ||
| expect(result.data?.payment_qr_spayd).toContain("CC:CZK") | ||
| expect(result.data?.payment_qr_spayd).toContain("X-VS:1234567890") | ||
| expect(result.data?.payment_qr_data_url).toEqual( | ||
| expect.stringMatching(PNG_DATA_URL_PATTERN) | ||
| ) | ||
| expect(result.data?.qr_payment).toMatchObject({ | ||
| amount: 1234.5, | ||
| currency_code: "CZK", | ||
| iban: "CZ6508000000192000145399", | ||
| reference: "1234567890", | ||
| }) | ||
| }) | ||
|
|
||
| it("loads IBAN from the qr payment module", async () => { | ||
| const getIban = vi.fn().mockResolvedValue("CZ6508000000192000145399") | ||
| const provider = new QrManualPaymentProvider({ | ||
| [QR_PAYMENT_MODULE]: { getIban }, | ||
| }) | ||
|
|
||
| const result = await provider.initiatePayment({ | ||
| amount: 100, | ||
| currency_code: "CZK", | ||
| data: { | ||
| reference: "987654321", | ||
| }, | ||
| }) | ||
|
|
||
| expect(getIban).toHaveBeenCalled() | ||
| expect(result.data?.payment_qr_spayd).toContain("X-VS:987654321") | ||
| }) | ||
|
|
||
| it("preserves the existing QR payment reference when payment amount changes", async () => { | ||
| const getIban = vi.fn().mockResolvedValue("CZ6508000000192000145399") | ||
| const provider = new QrManualPaymentProvider({ | ||
| [QR_PAYMENT_MODULE]: { getIban }, | ||
| }) | ||
|
|
||
| const result = await provider.updatePayment({ | ||
| amount: 250, | ||
| currency_code: "CZK", | ||
| data: { | ||
| qr_payment: { | ||
| reference: "1234567890", | ||
| }, | ||
| }, | ||
| context: { | ||
| idempotency_key: "new-idempotency-key", | ||
| }, | ||
| }) | ||
|
|
||
| expect(result.id).toBe("1234567890") | ||
| expect(result.data?.payment_qr_spayd).toContain("AM:250.00") | ||
| expect(result.data?.payment_qr_spayd).toContain("X-VS:1234567890") | ||
| expect(result.data?.qr_payment).toMatchObject({ | ||
| reference: "1234567890", | ||
| }) | ||
| }) | ||
|
|
||
| it("authorizes the manual QR payment so checkout can create an order", async () => { | ||
| const provider = new QrManualPaymentProvider({}) | ||
|
|
||
| await expect( | ||
| provider.authorizePayment({ | ||
| data: { | ||
| payment_qr_spayd: "SPD*1.0", | ||
| }, | ||
| }) | ||
| ).resolves.toEqual({ | ||
| status: "authorized", | ||
| data: { | ||
| payment_qr_spayd: "SPD*1.0", | ||
| }, | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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,5 @@ | ||
| export const QR_PAYMENT_MODULE = "qr_payment" | ||
| export const QR_PAYMENT_CONFIG_SERVICE = "qrPaymentConfigService" | ||
| export const QR_PAYMENT_PROVIDER_IDENTIFIER = "qr_manual" | ||
| export const QR_PAYMENT_PROVIDER_ID = "default" | ||
| export const QR_PAYMENT_MEDUSA_PROVIDER_ID = `pp_${QR_PAYMENT_PROVIDER_IDENTIFIER}_${QR_PAYMENT_PROVIDER_ID}` |
3 changes: 2 additions & 1 deletion
3
...medusa-be/src/modules/qr-payment/index.ts → ...medusa-be/src/modules/payment-qr/index.ts
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...dusa-be/src/modules/qr-payment/service.ts → ...dusa-be/src/modules/payment-qr/service.ts
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.