Add types for payment webhooks (#212)
* Add types for payment webhooks * Add transaction webhooks * Update responses for transactions * Create .changeset/gold-buses-warn.md * Simplify returned values for some webhooks * Update changesets --------- Co-authored-by: Lukasz Ostrowski <lukasz@monolog.tech>
This commit is contained in:
parent
0deb0fac22
commit
b108460435
7 changed files with 90 additions and 12 deletions
12
.changeset/gold-buses-warn.md
Normal file
12
.changeset/gold-buses-warn.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
"@saleor/app-sdk": patch
|
||||
---
|
||||
|
||||
Added definitions for new sync events for payments:
|
||||
|
||||
- `TRANSACTION_CHARGE_REQUESTED`
|
||||
- `TRANSACTION_REFUND_REQUESTED`
|
||||
- `TRANSACTION_CANCELATION_REQUESTED`
|
||||
- `PAYMENT_GATEWAY_INITIALIZE_SESSION`
|
||||
- `TRANSACTION_INITIALIZE_SESSION`
|
||||
- `TRANSACTION_PROCESS_SESSION`
|
8
.github/workflows/assign-pr.yml
vendored
8
.github/workflows/assign-pr.yml
vendored
|
@ -8,7 +8,7 @@ jobs:
|
|||
assign_creator:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Assign PR to creator
|
||||
uses: thomaseizinger/assign-pr-creator-action@v1.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Assign PR to creator
|
||||
uses: thomaseizinger/assign-pr-creator-action@v1.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
@ -46,7 +46,7 @@ localStorage.debug = "*";
|
|||
Use the namespace name to enable debug logs for each module.
|
||||
|
||||
| Namespace name | Description |
|
||||
|-------------------------------|----------------------------------------------------|
|
||||
| ----------------------------- | -------------------------------------------------- |
|
||||
| \app-sdk:\* | Enable all |
|
||||
| app-sdk:AppBridge | Enable [AppBridge](./app-bridge.md) (browser only) |
|
||||
| app-sdk:Middleware:\* | Enable all middlewares (node only) |
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"test": "vitest",
|
||||
"test:ci": "CI=true vitest --coverage --silent",
|
||||
"prepare": "husky install",
|
||||
"lint": "prettier --loglevel warn --write . && eslint --fix .",
|
||||
"lint": "tsc --noEmit && prettier --loglevel warn --write . && eslint --fix .",
|
||||
"copy-readme": "cp README.md dist/README.md",
|
||||
"publish:ci": "pnpm publish && npx changeset tag && git push --follow-tags"
|
||||
},
|
||||
|
|
|
@ -48,13 +48,13 @@ describe("SaleorSyncWebhook", () => {
|
|||
ctx.buildResponse({
|
||||
lines: [
|
||||
{
|
||||
tax_rate: "VAT8",
|
||||
tax_rate: 8,
|
||||
total_net_amount: 10,
|
||||
total_gross_amount: 1.08,
|
||||
},
|
||||
],
|
||||
shipping_price_gross_amount: 2,
|
||||
shipping_tax_rate: "VAT8",
|
||||
shipping_tax_rate: 8,
|
||||
shipping_price_net_amount: 1,
|
||||
})
|
||||
);
|
||||
|
@ -66,13 +66,13 @@ describe("SaleorSyncWebhook", () => {
|
|||
expect.objectContaining({
|
||||
lines: [
|
||||
{
|
||||
tax_rate: "VAT8",
|
||||
tax_rate: 8,
|
||||
total_net_amount: 10,
|
||||
total_gross_amount: 1.08,
|
||||
},
|
||||
],
|
||||
shipping_price_gross_amount: 2,
|
||||
shipping_tax_rate: "VAT8",
|
||||
shipping_tax_rate: 8,
|
||||
shipping_price_net_amount: 1,
|
||||
})
|
||||
);
|
||||
|
|
|
@ -29,6 +29,67 @@ export type SyncWebhookResponsesMap = {
|
|||
*/
|
||||
maximum_delivery_days?: number;
|
||||
}>;
|
||||
TRANSACTION_CHARGE_REQUESTED: {
|
||||
pspReference: string;
|
||||
result?: "CHARGE_SUCCESS" | "CHARGE_FAILURE";
|
||||
amount?: number;
|
||||
time?: string;
|
||||
externalUrl?: string;
|
||||
message?: string;
|
||||
};
|
||||
TRANSACTION_REFUND_REQUESTED: {
|
||||
pspReference: string;
|
||||
result?: "REFUND_SUCCESS" | "REFUND_FAILURE";
|
||||
amount?: number;
|
||||
time?: string;
|
||||
externalUrl?: string;
|
||||
message?: string;
|
||||
};
|
||||
TRANSACTION_CANCELATION_REQUESTED: {
|
||||
pspReference: string;
|
||||
result?: "CANCEL_SUCCESS" | "CANCEL_FAILURE";
|
||||
amount?: number;
|
||||
time?: string;
|
||||
externalUrl?: string;
|
||||
message?: string;
|
||||
};
|
||||
PAYMENT_GATEWAY_INITIALIZE_SESSION: {
|
||||
data: unknown;
|
||||
};
|
||||
TRANSACTION_INITIALIZE_SESSION: {
|
||||
pspReference?: string;
|
||||
data?: unknown;
|
||||
result:
|
||||
| "CHARGE_SUCCESS"
|
||||
| "CHARGE_FAILURE"
|
||||
| "CHARGE_REQUESTED"
|
||||
| "CHARGE_ACTION_REQUIRED"
|
||||
| "AUTHORIZATION_SUCCESS"
|
||||
| "AUTHORIZATION_FAILURE"
|
||||
| "AUTHORIZATION_REQUESTED"
|
||||
| "AUTHORIZATION_ACTION_REQUIRED";
|
||||
amount: number;
|
||||
time?: string;
|
||||
externalUrl?: string;
|
||||
message?: string;
|
||||
};
|
||||
TRANSACTION_PROCESS_SESSION: {
|
||||
pspReference?: string;
|
||||
data?: unknown;
|
||||
result:
|
||||
| "CHARGE_SUCCESS"
|
||||
| "CHARGE_FAILURE"
|
||||
| "CHARGE_REQUESTED"
|
||||
| "CHARGE_ACTION_REQUIRED"
|
||||
| "AUTHORIZATION_SUCCESS"
|
||||
| "AUTHORIZATION_FAILURE"
|
||||
| "AUTHORIZATION_REQUESTED"
|
||||
| "AUTHORIZATION_ACTION_REQUIRED";
|
||||
amount: number;
|
||||
time?: string;
|
||||
externalUrl?: string;
|
||||
message?: string;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -167,14 +167,19 @@ export type AsyncWebhookEventType =
|
|||
/**
|
||||
* @see https://github.com/saleor/saleor/blob/main/saleor/graphql/schema.graphql#L1995
|
||||
*
|
||||
* TODO Add Payment events after new API in 3.13
|
||||
*/
|
||||
export type SyncWebhookEventType =
|
||||
| "CHECKOUT_CALCULATE_TAXES"
|
||||
| "ORDER_CALCULATE_TAXES"
|
||||
| "SHIPPING_LIST_METHODS_FOR_CHECKOUT"
|
||||
| "CHECKOUT_FILTER_SHIPPING_METHODS"
|
||||
| "ORDER_FILTER_SHIPPING_METHODS";
|
||||
| "ORDER_FILTER_SHIPPING_METHODS"
|
||||
| "TRANSACTION_CHARGE_REQUESTED"
|
||||
| "TRANSACTION_REFUND_REQUESTED"
|
||||
| "TRANSACTION_CANCELATION_REQUESTED"
|
||||
| "PAYMENT_GATEWAY_INITIALIZE_SESSION"
|
||||
| "TRANSACTION_INITIALIZE_SESSION"
|
||||
| "TRANSACTION_PROCESS_SESSION";
|
||||
|
||||
export interface AppExtension {
|
||||
/** Name which will be displayed in the dashboard */
|
||||
|
|
Loading…
Reference in a new issue