Skip to content
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

feat: authorize webhooks #57

Merged
merged 33 commits into from
Jan 9, 2024
Merged

feat: authorize webhooks #57

merged 33 commits into from
Jan 9, 2024

Conversation

peelar
Copy link
Member

@peelar peelar commented Dec 14, 2023

This PR adds functionality for:

  • registering Authorize.net webhooks in the app (src/modules/authorize-net/webhook/authorize-net-webhook-client.ts, src/modules/authorize-net/webhook/authorize-net-webhook-manager.ts)
  • handling the Authorize.net webhooks (src/modules/authorize-net/webhook/authorize-net-webhook-handler.ts)
  • enclosing the two-way transaction synchronization between Saleor and Authorize.net (src/modules/authorize-net/synchronized-transaction/saleor-transaction-id-converter.ts, src/modules/authorize-net/synchronized-transaction/create-synchronized-transaction-request.ts, src/modules/authorize-net/synchronized-transaction/synchronized-transaction-id-resolver.ts)

Next up:

  • removing multiple channel connections functionality
  • domain whitelist instead of providing AUTHORIZE_PAYMENT_FORM_URL env variable
  • mapping the rest of the transaction fields

Copy link

changeset-bot bot commented Dec 14, 2023

🦋 Changeset detected

Latest commit: a0db74e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
saleor-app-authorize-net Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 14, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-app-payment-authorize-net ❌ Failed (Inspect) Jan 9, 2024 0:20am

@peelar peelar marked this pull request as ready for review January 8, 2024 10:03
@peelar peelar requested a review from a team as a code owner January 8, 2024 10:03
Copy link

github-actions bot commented Jan 8, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
69.88% (-9.06% 🔻)
450/644
🟢 Branches
85.71% (-2.69% 🔻)
36/42
🔴 Functions
42.11% (-26.08% 🔻)
16/38
🟡 Lines
69.88% (-9.06% 🔻)
450/644
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 errors.ts
90% (-10% 🔻)
100%
0% (-100% 🔻)
90% (-10% 🔻)
🔴
... / app-configurator.ts
59% (-25.09% 🔻)
85.71% (+5.71% 🔼)
38.46% (-36.54% 🔻)
59% (-25.09% 🔻)

Test suite run success

40 tests passing in 18 suites.

Report generated by 🧪jest coverage report action from a0db74e

src/lib/env.mjs Outdated
AUTHORIZE_SIGNATURE_KEY: z
.string()
.min(1)
// .optional()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed

@@ -0,0 +1,22 @@
import { type NextApiRequest, type NextApiResponse } from "next";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue with checking the HMAC could be caused by default NextJS body parser. I had to turn it off in case of calculating checksums for the Stripe or GitHub webhooks.

References:

}

private getWebhookParams() {
const appUrl = isDevelopment() ? env.LOCAL_APP_URL : `https://${env.VERCEL_URL}`; // todo: get rid of it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would use APP_API_BASE_URL to have compatibility with existing apps.
https://github.com/saleor/apps/blob/main/apps/cms-v2/src/pages/api/manifest.ts#L13

"net.authorize.payment.refund.created",
],
status: "active",
url: `${appUrl}/api/webhooks/authorize`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Would use new URL to avoid issues when user provides base URL with trailing slash

@@ -12,7 +12,7 @@
},
"type": "module",
"scripts": {
"dev": "pnpm generate && next dev",
"dev": "pnpm generate && next dev --port 8000",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention the ports in the readme

@peelar
Copy link
Member Author

peelar commented Jan 9, 2024

feedback addressed @krzysztofwolski 🖖

README.md Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪


const normalizedError = normalizeError(error);
return responseBuilder.ok({
amount: 0, // 0 or real amount?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can get the real value, lets use it. If thats displayed in any way do the staff/customer, then theres a value in knowing exact value which got rejected

@peelar peelar merged commit 465dcc7 into main Jan 9, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants