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:
|
assign_creator:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Assign PR to creator
|
- name: Assign PR to creator
|
||||||
uses: thomaseizinger/assign-pr-creator-action@v1.0.0
|
uses: thomaseizinger/assign-pr-creator-action@v1.0.0
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
|
@ -46,7 +46,7 @@ localStorage.debug = "*";
|
||||||
Use the namespace name to enable debug logs for each module.
|
Use the namespace name to enable debug logs for each module.
|
||||||
|
|
||||||
| Namespace name | Description |
|
| Namespace name | Description |
|
||||||
|-------------------------------|----------------------------------------------------|
|
| ----------------------------- | -------------------------------------------------- |
|
||||||
| \app-sdk:\* | Enable all |
|
| \app-sdk:\* | Enable all |
|
||||||
| app-sdk:AppBridge | Enable [AppBridge](./app-bridge.md) (browser only) |
|
| app-sdk:AppBridge | Enable [AppBridge](./app-bridge.md) (browser only) |
|
||||||
| app-sdk:Middleware:\* | Enable all middlewares (node only) |
|
| app-sdk:Middleware:\* | Enable all middlewares (node only) |
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:ci": "CI=true vitest --coverage --silent",
|
"test:ci": "CI=true vitest --coverage --silent",
|
||||||
"prepare": "husky install",
|
"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",
|
"copy-readme": "cp README.md dist/README.md",
|
||||||
"publish:ci": "pnpm publish && npx changeset tag && git push --follow-tags"
|
"publish:ci": "pnpm publish && npx changeset tag && git push --follow-tags"
|
||||||
},
|
},
|
||||||
|
|
|
@ -48,13 +48,13 @@ describe("SaleorSyncWebhook", () => {
|
||||||
ctx.buildResponse({
|
ctx.buildResponse({
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
tax_rate: "VAT8",
|
tax_rate: 8,
|
||||||
total_net_amount: 10,
|
total_net_amount: 10,
|
||||||
total_gross_amount: 1.08,
|
total_gross_amount: 1.08,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
shipping_price_gross_amount: 2,
|
shipping_price_gross_amount: 2,
|
||||||
shipping_tax_rate: "VAT8",
|
shipping_tax_rate: 8,
|
||||||
shipping_price_net_amount: 1,
|
shipping_price_net_amount: 1,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -66,13 +66,13 @@ describe("SaleorSyncWebhook", () => {
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
lines: [
|
lines: [
|
||||||
{
|
{
|
||||||
tax_rate: "VAT8",
|
tax_rate: 8,
|
||||||
total_net_amount: 10,
|
total_net_amount: 10,
|
||||||
total_gross_amount: 1.08,
|
total_gross_amount: 1.08,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
shipping_price_gross_amount: 2,
|
shipping_price_gross_amount: 2,
|
||||||
shipping_tax_rate: "VAT8",
|
shipping_tax_rate: 8,
|
||||||
shipping_price_net_amount: 1,
|
shipping_price_net_amount: 1,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,6 +29,67 @@ export type SyncWebhookResponsesMap = {
|
||||||
*/
|
*/
|
||||||
maximum_delivery_days?: number;
|
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
|
* @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 =
|
export type SyncWebhookEventType =
|
||||||
| "CHECKOUT_CALCULATE_TAXES"
|
| "CHECKOUT_CALCULATE_TAXES"
|
||||||
| "ORDER_CALCULATE_TAXES"
|
| "ORDER_CALCULATE_TAXES"
|
||||||
| "SHIPPING_LIST_METHODS_FOR_CHECKOUT"
|
| "SHIPPING_LIST_METHODS_FOR_CHECKOUT"
|
||||||
| "CHECKOUT_FILTER_SHIPPING_METHODS"
|
| "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 {
|
export interface AppExtension {
|
||||||
/** Name which will be displayed in the dashboard */
|
/** Name which will be displayed in the dashboard */
|
||||||
|
|
Loading…
Reference in a new issue