@siglume/direct-request-payment 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,15 @@
1
1
  import express from "express";
2
2
  import {
3
- createDirectRequestPaymentChallenge,
4
- DirectRequestPaymentClient,
3
+ DirectRequestPaymentMerchantClient,
5
4
  verifyDirectRequestPaymentWebhook,
6
5
  } from "@siglume/direct-request-payment";
7
6
 
8
7
  const app = express();
9
8
  const port = Number(process.env.PORT || 3000);
10
9
  const merchantKey = process.env.SIGLUME_DIRECT_PAYMENT_MERCHANT || "example_merchant";
10
+ const siglumeMerchant = new DirectRequestPaymentMerchantClient({
11
+ auth_token: process.env.SIGLUME_MERCHANT_AUTH_TOKEN,
12
+ });
11
13
 
12
14
  // Use JSON for normal routes. Use raw body only on the webhook route.
13
15
  app.use((req, res, next) => {
@@ -35,49 +37,29 @@ app.post("/checkout/siglume/start", asyncRoute(async (req, res) => {
35
37
  }
36
38
 
37
39
  order.payment_attempt = Number(order.payment_attempt || 0) + 1;
38
- const challenge = await createDirectRequestPaymentChallenge({
40
+ const session = await siglumeMerchant.createCheckoutSession({
39
41
  merchant: merchantKey,
40
42
  amount_minor: order.amount_minor,
41
43
  currency: order.currency,
42
- secret: process.env.SIGLUME_DIRECT_PAYMENT_CHALLENGE_SECRET!,
43
44
  nonce: `${order.id}-attempt_${order.payment_attempt}`,
45
+ success_url: `${process.env.SHOP_PUBLIC_ORIGIN || "https://shop.example.com"}/thanks`,
46
+ cancel_url: `${process.env.SHOP_PUBLIC_ORIGIN || "https://shop.example.com"}/cart`,
47
+ metadata: { order_id: order.id },
44
48
  });
45
49
 
46
- order.siglume_challenge_hash = challenge.challenge_hash;
50
+ order.siglume_challenge_hash = session.challenge_hash;
51
+ order.siglume_checkout_session_id = session.session_id;
47
52
  order.siglume_payment_status = "pending";
48
53
 
49
54
  res.json({
50
55
  order_id: order.id,
51
56
  amount_minor: order.amount_minor,
52
57
  currency: order.currency,
53
- siglume_challenge: challenge.challenge,
58
+ checkout_url: session.checkout_url,
59
+ session_id: session.session_id,
54
60
  });
55
61
  }));
56
62
 
57
- app.post("/checkout/siglume/pay", asyncRoute(async (req, res) => {
58
- const order = orders.get(String(req.body.order_id || ""));
59
- if (!order) {
60
- res.status(404).json({ error: "order_not_found" });
61
- return;
62
- }
63
-
64
- // In production, obtain this from the authenticated buyer's Siglume session
65
- // or a hosted Siglume payment confirmation flow. Do not use a merchant secret
66
- // to charge a customer wallet.
67
- const siglume = new DirectRequestPaymentClient({
68
- auth_token: String(req.headers.authorization || "").replace(/^Bearer\s+/i, ""),
69
- });
70
-
71
- const requirement = await siglume.createPaymentRequirement({
72
- merchant: merchantKey,
73
- amount_minor: order.amount_minor,
74
- currency: order.currency,
75
- challenge: String(req.body.siglume_challenge || ""),
76
- });
77
-
78
- res.json({ requirement });
79
- }));
80
-
81
63
  app.post("/siglume/webhook", express.raw({ type: "application/json" }), asyncRoute(async (req, res) => {
82
64
  const header = String(req.headers["siglume-signature"] || "");
83
65
  const { event } = await verifyDirectRequestPaymentWebhook(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siglume/direct-request-payment",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "SDK for the Siglume Direct Request Payment SDRP payment protocol",
5
5
  "keywords": [
6
6
  "siglume",