@mintmoney/react 0.1.0-alpha.36 → 0.1.0-alpha.37
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.
- package/dist/css/styles.css +45 -65
- package/dist/docs/card-payments.md +65 -0
- package/dist/docs/customisation.md +67 -0
- package/dist/docs/overview.md +19 -0
- package/dist/docs/quickstart.md +174 -0
- package/dist/esm/api/generated.js +1458 -2
- package/dist/esm/api/generated.js.map +1 -1
- package/dist/esm/api/payments.js +89 -4
- package/dist/esm/api/payments.js.map +1 -1
- package/dist/esm/checkout/index.js +45 -4
- package/dist/esm/checkout/index.js.map +1 -1
- package/dist/esm/checkout/launcher.js +6 -0
- package/dist/esm/checkout/launcher.js.map +1 -0
- package/dist/esm/checkout/modal.js +19 -14
- package/dist/esm/checkout/modal.js.map +1 -1
- package/dist/esm/checkout/payment-methods/providers.js +15 -0
- package/dist/esm/checkout/payment-methods/providers.js.map +1 -0
- package/dist/esm/checkout/resume-state.js +105 -0
- package/dist/esm/checkout/resume-state.js.map +1 -1
- package/dist/esm/checkout/views/amount-header.js +45 -5
- package/dist/esm/checkout/views/amount-header.js.map +1 -1
- package/dist/esm/checkout/views/card-intent/customer-details.js +108 -0
- package/dist/esm/checkout/views/card-intent/customer-details.js.map +1 -0
- package/dist/esm/checkout/views/card-intent/details.js +271 -21
- package/dist/esm/checkout/views/card-intent/details.js.map +1 -1
- package/dist/esm/checkout/views/card-intent/processing.js +42 -0
- package/dist/esm/checkout/views/card-intent/processing.js.map +1 -0
- package/dist/esm/checkout/views/card-intent/submission.js +85 -0
- package/dist/esm/checkout/views/card-intent/submission.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/direct-details.js +49 -165
- package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js +112 -0
- package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js +69 -0
- package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/processing.js +15 -6
- package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/success.js +5 -1
- package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
- package/dist/esm/checkout/views/initial.js +14 -2
- package/dist/esm/checkout/views/initial.js.map +1 -1
- package/dist/esm/checkout/views/method-select.js +1 -1
- package/dist/esm/checkout/views/method-select.js.map +1 -1
- package/dist/esm/components/inputs/index.js +25 -10
- package/dist/esm/components/inputs/index.js.map +1 -1
- package/dist/esm/components/modals/modal-with-views.js +3 -4
- package/dist/esm/components/modals/modal-with-views.js.map +1 -1
- package/dist/esm/refund/confirmation.js +30 -0
- package/dist/esm/refund/confirmation.js.map +1 -0
- package/dist/esm/refund/index.js +11 -57
- package/dist/esm/refund/index.js.map +1 -1
- package/dist/esm/refund/prepare-guard.js +1 -1
- package/dist/esm/refund/prepare-guard.js.map +1 -1
- package/dist/esm/state/checkout/store.js +81 -24
- package/dist/esm/state/checkout/store.js.map +1 -1
- package/dist/types/api/generated.d.ts +5680 -224
- package/dist/types/api/generated.d.ts.map +1 -1
- package/dist/types/api/payments.d.ts +59 -5
- package/dist/types/api/payments.d.ts.map +1 -1
- package/dist/types/checkout/index.d.ts +2 -1
- package/dist/types/checkout/index.d.ts.map +1 -1
- package/dist/types/checkout/launcher.d.ts +6 -0
- package/dist/types/checkout/launcher.d.ts.map +1 -0
- package/dist/types/checkout/modal.d.ts +1 -0
- package/dist/types/checkout/modal.d.ts.map +1 -1
- package/dist/types/checkout/payment-methods/providers.d.ts +13 -0
- package/dist/types/checkout/payment-methods/providers.d.ts.map +1 -0
- package/dist/types/checkout/resume-state.d.ts +14 -0
- package/dist/types/checkout/resume-state.d.ts.map +1 -1
- package/dist/types/checkout/views/amount-header.d.ts +1 -0
- package/dist/types/checkout/views/amount-header.d.ts.map +1 -1
- package/dist/types/checkout/views/card-intent/customer-details.d.ts +10 -0
- package/dist/types/checkout/views/card-intent/customer-details.d.ts.map +1 -0
- package/dist/types/checkout/views/card-intent/details.d.ts +3 -1
- package/dist/types/checkout/views/card-intent/details.d.ts.map +1 -1
- package/dist/types/checkout/views/card-intent/processing.d.ts +5 -0
- package/dist/types/checkout/views/card-intent/processing.d.ts.map +1 -0
- package/dist/types/checkout/views/card-intent/submission.d.ts +8 -0
- package/dist/types/checkout/views/card-intent/submission.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +1 -1
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts +20 -0
- package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts +16 -0
- package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/processing.d.ts +3 -0
- package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
- package/dist/types/checkout/views/initial.d.ts.map +1 -1
- package/dist/types/checkout/views/method-select.d.ts.map +1 -1
- package/dist/types/components/inputs/index.d.ts +1 -1
- package/dist/types/components/inputs/index.d.ts.map +1 -1
- package/dist/types/components/modals/modal-with-views.d.ts +0 -1
- package/dist/types/components/modals/modal-with-views.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +1 -1
- package/dist/types/refund/confirmation.d.ts +14 -0
- package/dist/types/refund/confirmation.d.ts.map +1 -0
- package/dist/types/refund/index.d.ts.map +1 -1
- package/dist/types/refund/prepare-guard.d.ts +1 -0
- package/dist/types/refund/prepare-guard.d.ts.map +1 -1
- package/dist/types/state/checkout/store.d.ts +6 -4
- package/dist/types/state/checkout/store.d.ts.map +1 -1
- package/package.json +11 -8
- package/dist/esm/checkout/views/fiat-intent/bank-payment.js +0 -35
- package/dist/esm/checkout/views/fiat-intent/bank-payment.js.map +0 -1
- package/dist/esm/refund/prepare-signing.js +0 -29
- package/dist/esm/refund/prepare-signing.js.map +0 -1
- package/dist/types/checkout/views/fiat-intent/bank-payment.d.ts +0 -2
- package/dist/types/checkout/views/fiat-intent/bank-payment.d.ts.map +0 -1
- package/dist/types/refund/prepare-signing.d.ts +0 -17
- package/dist/types/refund/prepare-signing.d.ts.map +0 -1
package/dist/css/styles.css
CHANGED
|
@@ -80,90 +80,70 @@
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/*
|
|
84
|
-
.mm-modal-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
/* Card checkout: a single, focused payment sheet. */
|
|
84
|
+
.mm-checkout-modal.mm-modal-view-cardIntent {
|
|
85
|
+
height: min(760px, calc(100dvh - 40px)) !important;
|
|
86
|
+
max-height: min(760px, calc(100dvh - 40px)) !important;
|
|
87
|
+
padding: 28px !important;
|
|
88
|
+
border: 1px solid rgba(148, 163, 184, 0.25);
|
|
89
|
+
border-radius: 24px;
|
|
90
|
+
box-shadow: 0 28px 80px rgba(15, 23, 42, 0.24);
|
|
91
|
+
overflow: hidden !important;
|
|
92
|
+
overflow-x: hidden !important;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Do not leave a scrollable, full-height sheet behind while Evervault loads. */
|
|
96
|
+
.mm-checkout-modal.mm-modal-view-cardIntent:has(
|
|
97
|
+
[data-card-form-loading="true"]
|
|
98
|
+
) {
|
|
99
|
+
height: auto !important;
|
|
100
|
+
min-height: 300px;
|
|
95
101
|
}
|
|
96
102
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
view-transition-name: none !important;
|
|
100
|
-
view-transition-containment: none !important;
|
|
103
|
+
.mm-modal-view-cardIntent .mm-modal-body:has([data-card-form-loading="true"]) {
|
|
104
|
+
overflow: hidden;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
|
-
.mm-modal-
|
|
104
|
-
|
|
105
|
-
display: flex;
|
|
106
|
-
flex-direction: column;
|
|
107
|
-
min-width: 0;
|
|
107
|
+
.mm-modal-view-cardIntent .mm-modal-nav {
|
|
108
|
+
margin-bottom: 20px;
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
.mm-modal-
|
|
111
|
-
|
|
111
|
+
.mm-modal-view-cardIntent .mm-modal-header {
|
|
112
|
+
padding-bottom: 22px;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
|
-
.mm-modal-
|
|
115
|
-
flex:
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
.mm-modal-view-cardIntent .mm-modal-body {
|
|
116
|
+
flex: 1 1 auto;
|
|
117
|
+
min-height: 0;
|
|
118
|
+
overflow-y: auto;
|
|
119
|
+
overflow-x: hidden;
|
|
120
|
+
overscroll-behavior: contain;
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
.mm-modal-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
.mm-modal-view-cardIntent .mm-card-frame iframe {
|
|
124
|
+
width: 100% !important;
|
|
125
|
+
height: var(--mm-card-frame-height) !important;
|
|
126
|
+
min-height: 0 !important;
|
|
127
|
+
border: 0;
|
|
128
|
+
border-radius: 12px;
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
.mm-modal-
|
|
128
|
-
|
|
129
|
-
height:
|
|
130
|
-
min-height: 600px;
|
|
131
|
-
border: 1px solid #e5e7eb;
|
|
132
|
-
border-radius: 8px;
|
|
131
|
+
.mm-modal-view-cardIntent .mm-modal-content {
|
|
132
|
+
flex: 1 1 auto;
|
|
133
|
+
min-height: 0;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
/* Responsive design for two-column layout */
|
|
136
136
|
@media (max-width: 768px) {
|
|
137
|
-
.mm-modal-
|
|
138
|
-
|
|
139
|
-
height: 100dvh !important;
|
|
140
|
-
max-width: 100vw !important;
|
|
141
|
-
max-height: 100dvh !important;
|
|
142
|
-
min-width: 100vw !important;
|
|
143
|
-
min-height: 100dvh !important;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.mm-modal-two-column-layout {
|
|
147
|
-
flex-direction: column;
|
|
148
|
-
gap: 16px;
|
|
149
|
-
height: 100%;
|
|
150
|
-
flex: 1;
|
|
137
|
+
.mm-checkout-modal.mm-modal-view-cardIntent {
|
|
138
|
+
padding: 24px 20px calc(20px + env(safe-area-inset-bottom, 0px)) !important;
|
|
151
139
|
}
|
|
152
140
|
|
|
153
|
-
.mm-modal-
|
|
154
|
-
|
|
155
|
-
min-height: auto;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.mm-modal-right-column {
|
|
159
|
-
flex: 1;
|
|
160
|
-
min-height: 0;
|
|
141
|
+
.mm-modal-view-cardIntent .mm-modal-nav {
|
|
142
|
+
margin-bottom: 16px;
|
|
161
143
|
}
|
|
162
144
|
|
|
163
|
-
.mm-modal-
|
|
164
|
-
|
|
165
|
-
height: 100% !important;
|
|
166
|
-
border-radius: 6px;
|
|
145
|
+
.mm-modal-view-cardIntent .mm-modal-header {
|
|
146
|
+
padding-bottom: 20px;
|
|
167
147
|
}
|
|
168
148
|
}
|
|
169
149
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Card payments
|
|
2
|
+
|
|
3
|
+
Card checkout is provider-neutral from an SDK consumer's perspective. Mint selects the enabled card provider in the public checkout configuration; when that provider and an Evervault collection configuration are available, the standard `Checkout` component adds **Pay by Card** automatically.
|
|
4
|
+
|
|
5
|
+
The payer enters their card inside Evervault's hosted iframe. The SDK accepts only Evervault-encrypted card number and CVC values, then submits those values to Mint using an idempotent fiat-attempt request. Raw PAN and CVC values do not pass through Mint React state or the merchant application.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Use a Mint API environment with fiat card payments enabled.
|
|
10
|
+
- Mint Admin must first approve the card provider for the organization. A merchant admin then enables that provider under **Payment methods** and applies it to all or selected checkouts.
|
|
11
|
+
- Configure the Evervault Team ID and App ID on the Mint API. These identifiers are public; Evervault API keys remain server-side.
|
|
12
|
+
- Configure BXNK and the authenticated Evervault Relay on the Mint API. Never put BXNK access keys, BXNK secrets, webhook secrets, or Evervault API keys in browser code.
|
|
13
|
+
|
|
14
|
+
### Content Security Policy
|
|
15
|
+
|
|
16
|
+
If your site sends a Content Security Policy, merge these Evervault origins
|
|
17
|
+
into its existing directives (do not replace the policy wholesale):
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
script-src https://js.evervault.com
|
|
21
|
+
connect-src https://keys.evervault.com https://api.evervault.com
|
|
22
|
+
frame-src https://ui-components.evervault.com
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
3D Secure may leave your site briefly for a bank challenge. If your navigation
|
|
26
|
+
policy restricts top-level destinations, allow the card provider's challenge
|
|
27
|
+
destination as required by that provider.
|
|
28
|
+
|
|
29
|
+
No additional React component is required. Continue using the normal checkout integration:
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
<Checkout
|
|
33
|
+
createPayment={createPayment}
|
|
34
|
+
resumeKey={`order:${orderId}`}
|
|
35
|
+
onSuccess={handleSuccess}
|
|
36
|
+
>
|
|
37
|
+
<button>Pay now</button>
|
|
38
|
+
</Checkout>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`resumeKey` must be stable for the merchant order across a full-page 3D Secure
|
|
42
|
+
redirect. It also prevents another `Checkout` mounted on the same page from
|
|
43
|
+
claiming that order's callback.
|
|
44
|
+
|
|
45
|
+
## Payment lifecycle
|
|
46
|
+
|
|
47
|
+
1. Evervault returns encrypted card fields to the SDK.
|
|
48
|
+
2. The SDK creates one idempotent Mint fiat payment attempt.
|
|
49
|
+
3. If BXNK requests 3D Secure verification, the checkout redirects the payer to the provider’s secure verification page.
|
|
50
|
+
4. Provider success advances the attempt to `settlement_pending`; it does not mark the Mint payment paid.
|
|
51
|
+
5. The standard payment-status view waits until Mint verifies direct splitter settlement. Only then does the normal checkout success callback run.
|
|
52
|
+
|
|
53
|
+
The card method remains hidden if either checkout enablement or the public Evervault collection configuration is missing. This fail-closed behavior lets operators disable the rail without shipping a new SDK build.
|
|
54
|
+
|
|
55
|
+
## Testing
|
|
56
|
+
|
|
57
|
+
Use BXNK and Evervault sandbox configuration with a test checkout. Card test payments intentionally use the provider sandbox instead of Mint's synthetic crypto success/failure picker, so OTP, provider-status, webhook, and settlement-pending behavior are exercised.
|
|
58
|
+
|
|
59
|
+
Use the BXNK Visa sandbox card below:
|
|
60
|
+
|
|
61
|
+
- Card number: `4295 5500 3172 6664`
|
|
62
|
+
- Expiry: `05/27`
|
|
63
|
+
- CVC: `390`
|
|
64
|
+
|
|
65
|
+
The hosted Mint payment page must consume a published SDK version containing card support. Updating this repository alone does not change the hosted page until that SDK version is published and the platform dependency is bumped.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Customisation
|
|
2
|
+
|
|
3
|
+
## MintMoney UI Namespace (`mm-`)
|
|
4
|
+
|
|
5
|
+
### 🎯 What is the `mm-` Namespace?
|
|
6
|
+
|
|
7
|
+
The **`mm-` namespace** is a **CSS class prefix** used in MintMoney UI to:
|
|
8
|
+
|
|
9
|
+
- **Scope styles** to MintMoney components.
|
|
10
|
+
- **Prevent style conflicts** with other CSS in consuming applications.
|
|
11
|
+
- **Provide customization flexibility** through CSS variables.
|
|
12
|
+
|
|
13
|
+
### **Example of Namespace Usage**
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
.mm-button {
|
|
17
|
+
background-color: var(--mm-color-primary);
|
|
18
|
+
font-family: var(--mm-font-family);
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Customizing Fonts
|
|
23
|
+
|
|
24
|
+
MintMoney UI allows you to customize fonts using CSS variables. This ensures flexibility while maintaining a consistent
|
|
25
|
+
look across all components.
|
|
26
|
+
|
|
27
|
+
### 🎨 Default Font
|
|
28
|
+
|
|
29
|
+
By default, MintMoney UI uses **Nunito Sans** as the primary font:
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
.mm-root {
|
|
33
|
+
font-family: var(--mm-font-family, "Nunito Sans"), sans-serif;
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Overriding the default font
|
|
38
|
+
|
|
39
|
+
If you want to override the font for only a specific section, apply the CSS variable to a class.
|
|
40
|
+
|
|
41
|
+
```css
|
|
42
|
+
:root {
|
|
43
|
+
--mm-font-family: "Inter", sans-serif;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Surplus refund thresholds
|
|
48
|
+
|
|
49
|
+
The checkout success view only surfaces a surplus claim CTA when the refundable surplus is large enough to be useful. By default, MintMoney uses a raw token threshold of `1000000` base units for USDC/USDT-style stablecoins, which is `1.00` for 6-decimal assets. Unknown assets default to `0` so their refunds are not hidden accidentally.
|
|
50
|
+
|
|
51
|
+
You can override thresholds through `cryptoCheckoutConfig.surplusRefundMinimums`:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
createConfig("pk_test_...", {
|
|
55
|
+
checkoutId: "checkout_...",
|
|
56
|
+
cryptoCheckoutConfig: {
|
|
57
|
+
numBlockConfirmations: 1,
|
|
58
|
+
paymentConfirmationStatus: PaymentStatus.CONFIRMING_PAYMENT,
|
|
59
|
+
surplusRefundMinimums: [
|
|
60
|
+
{
|
|
61
|
+
symbol: "USDC",
|
|
62
|
+
minimumBaseUnits: "5000000",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Guides
|
|
2
|
+
|
|
3
|
+
This page demonstrates some of the built-in markdown extensions provided by VitePress.
|
|
4
|
+
|
|
5
|
+
## Syntax Highlighting
|
|
6
|
+
|
|
7
|
+
VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting:
|
|
8
|
+
|
|
9
|
+
**Input**
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
export default {
|
|
13
|
+
data() {
|
|
14
|
+
return {
|
|
15
|
+
msg: "Highlighted!",
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
```
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Quickstart
|
|
2
|
+
|
|
3
|
+
This guide walks you through integrating @mintmoney/react into your React application, including both frontend setup and backend integration.
|
|
4
|
+
|
|
5
|
+
## 🚀 Prerequisites
|
|
6
|
+
|
|
7
|
+
Before starting, ensure you have the following:
|
|
8
|
+
|
|
9
|
+
- ✅ A React application (React 18+)
|
|
10
|
+
- ✅ API Keys from your MintMoney dashboard
|
|
11
|
+
- ✅ A backend server (Node.js/Express recommended)
|
|
12
|
+
|
|
13
|
+
## 📥 Installation
|
|
14
|
+
|
|
15
|
+
Install @mintmoney/react in your project:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @mintmoney/react
|
|
19
|
+
# or
|
|
20
|
+
yarn add @mintmoney/react
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @mintmoney/react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 🛠️ SDK Setup
|
|
26
|
+
|
|
27
|
+
Add the MintMoneyProvider to your application's root component:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { createConfig } from "@mintmoney/react/config";
|
|
31
|
+
import { MintMoneyProvider } from "@mintmoney/react/context";
|
|
32
|
+
import "@mintmoney/react/css/styles.css"; // Import default styles
|
|
33
|
+
|
|
34
|
+
const config = createConfig("your-public-key", {
|
|
35
|
+
apiUrl: "https://api.mintmoney.com", // Your API URL
|
|
36
|
+
checkoutId: "your-checkout-id", // Your checkout ID
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const App = () => {
|
|
40
|
+
return (
|
|
41
|
+
<MintMoneyProvider config={config}>
|
|
42
|
+
<YourApp />
|
|
43
|
+
</MintMoneyProvider>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 🔒 Backend Integration
|
|
49
|
+
|
|
50
|
+
For security, always create payments through a server-side endpoint. Here's an example using Express:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Example using Express
|
|
54
|
+
app.post("/api/create-payment", async (req, res) => {
|
|
55
|
+
const { amount, currency } = req.body;
|
|
56
|
+
|
|
57
|
+
// Validate required fields
|
|
58
|
+
if (!amount || !currency) {
|
|
59
|
+
res.status(400).json({ error: "Missing required fields" });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
// Make request to MintMoney API
|
|
65
|
+
const response = await fetch(`${process.env.API_URL}/v1/payments`, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"x-api-key": process.env.API_SECRET_KEY,
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
amount: Number(amount), // Ensure amount is a number
|
|
73
|
+
currency: currency.toUpperCase(), // Ensure currency is uppercase
|
|
74
|
+
checkout_id: process.env.CHECKOUT_ID,
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const data = await response.json();
|
|
79
|
+
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
throw new Error(data.error || "Failed to create payment");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
res.json(data);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error("Payment creation error:", error);
|
|
87
|
+
res.status(500).json({
|
|
88
|
+
error:
|
|
89
|
+
error instanceof Error ? error.message : "Failed to create payment",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 💳 Using the Checkout Component
|
|
96
|
+
|
|
97
|
+
Add the Checkout component to your application:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { Checkout } from "@mintmoney/react";
|
|
101
|
+
|
|
102
|
+
function ProductPage() {
|
|
103
|
+
const orderId = "your-stable-order-id";
|
|
104
|
+
|
|
105
|
+
const handleCreatePayment = async () => {
|
|
106
|
+
// Call your server endpoint to create the payment
|
|
107
|
+
const response = await fetch("/api/create-payment", {
|
|
108
|
+
method: "POST",
|
|
109
|
+
headers: {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
amount: 10.99, // Amount in the currency's standard unit (e.g., dollars)
|
|
114
|
+
currency: "USD", // Currency code (e.g., USD, EUR)
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
const error = await response.json();
|
|
120
|
+
throw new Error(error.error || "Failed to create payment");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return response.json();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const handleSuccess = (paymentId: string) => {
|
|
127
|
+
// Handle successful payment
|
|
128
|
+
console.log("Payment successful:", paymentId);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const handleError = (error: Error) => {
|
|
132
|
+
// Handle payment error
|
|
133
|
+
console.error("Payment failed:", error);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<Checkout
|
|
138
|
+
createPayment={handleCreatePayment}
|
|
139
|
+
resumeKey={`order:${orderId}`}
|
|
140
|
+
onSuccess={handleSuccess}
|
|
141
|
+
onError={handleError}
|
|
142
|
+
>
|
|
143
|
+
{/* Optional: Custom trigger button */}
|
|
144
|
+
<button>Pay with Crypto</button>
|
|
145
|
+
</Checkout>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Checkout Component Props
|
|
151
|
+
|
|
152
|
+
| Prop | Type | Required | Description |
|
|
153
|
+
| --------------- | -------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `createPayment` | `() => Promise<Payment>` | Yes | Function that calls your server endpoint to create a payment. Must be implemented server-side. |
|
|
155
|
+
| `resumeKey` | `string` | Yes | Stable merchant order key used to restore only the owning checkout after 3D Secure. |
|
|
156
|
+
| `onSuccess` | `(paymentId: string) => Promise<void>` | No | Callback when payment is successful |
|
|
157
|
+
| `onError` | `(error: Error) => Promise<void>` | No | Callback when payment fails |
|
|
158
|
+
| `asChild` | `boolean` | No | Whether to use the child element as the trigger button |
|
|
159
|
+
| `children` | `ReactNode` | No | Custom trigger element when asChild is true |
|
|
160
|
+
|
|
161
|
+
## ⚠️ Security Considerations
|
|
162
|
+
|
|
163
|
+
- Never expose your API secret key in the frontend code
|
|
164
|
+
- Always create payments through a server-side endpoint
|
|
165
|
+
- Use environment variables to store sensitive credentials
|
|
166
|
+
- Implement proper error handling and validation on the server
|
|
167
|
+
- Use HTTPS for all API communications
|
|
168
|
+
|
|
169
|
+
## 📚 Next Steps
|
|
170
|
+
|
|
171
|
+
- Learn about [customizing the checkout experience](./customisation.md)
|
|
172
|
+
- Configure and test [card payments](./card-payments.md)
|
|
173
|
+
- Read the [overview guide](./overview.md) for more details about the SDK
|
|
174
|
+
- Check out our [example implementations](https://github.com/mintmoney/mintmoney-js/tree/main/examples) for more use cases
|