mainstack-payments 0.3.3 → 0.3.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.
- package/README.md +132 -50
- package/build/mainstack-payments.js +2273 -2271
- package/package.json +1 -1
- /package/build/src/pages/{Index.d.ts → index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
<!--@@joggrdoc@@-->
|
|
2
|
+
<!-- @joggr:version(v2):end -->
|
|
3
|
+
<!-- @joggr:warning:start -->
|
|
4
|
+
<!--
|
|
5
|
+
_ _ _ __ __ _ ____ _ _ ___ _ _ ____ _ _ _
|
|
6
|
+
| | | | | | \ \ / / / \ | _ \ | \ | | |_ _| | \ | | / ___| | | | | | |
|
|
7
|
+
| | | | | | \ \ /\ / / / _ \ | |_) | | \| | | | | \| | | | _ | | | | | |
|
|
8
|
+
|_| |_| |_| \ V V / / ___ \ | _ < | |\ | | | | |\ | | |_| | |_| |_| |_|
|
|
9
|
+
(_) (_) (_) \_/\_/ /_/ \_\ |_| \_\ |_| \_| |___| |_| \_| \____| (_) (_) (_)
|
|
10
|
+
|
|
11
|
+
This document is managed by Joggr. Editing this document could break Joggr's core features, i.e. our
|
|
12
|
+
ability to auto-maintain this document. Please use the Joggr editor to edit this document
|
|
13
|
+
(link at bottom of the page).
|
|
14
|
+
-->
|
|
15
|
+
<!-- @joggr:warning:end -->
|
|
7
16
|
## Installation
|
|
8
17
|
|
|
9
18
|
To install the Mainstack Payments library, you need to run the following command in your terminal:
|
|
10
19
|
|
|
11
|
-
```
|
|
20
|
+
```typescript
|
|
12
21
|
yarn add mainstack-payments
|
|
13
22
|
```
|
|
14
23
|
|
|
@@ -16,7 +25,7 @@ yarn add mainstack-payments
|
|
|
16
25
|
|
|
17
26
|
To use the Mainstack Payments library, you need to import the library into your project, and then pass a config object to `paymentConfig` prop.
|
|
18
27
|
|
|
19
|
-
```
|
|
28
|
+
```typescript
|
|
20
29
|
import { MainstackPayments } from "mainstack-payments";
|
|
21
30
|
|
|
22
31
|
export default function Home() {
|
|
@@ -29,39 +38,106 @@ export default function Home() {
|
|
|
29
38
|
}
|
|
30
39
|
```
|
|
31
40
|
|
|
41
|
+
You might also want to import the MainstackPaymentsProvider in your root file if you see some styling on elements not looking appropraite.
|
|
42
|
+
|
|
43
|
+
```typescriptreact
|
|
44
|
+
const MainstackPaymentsProvider = dynamic(
|
|
45
|
+
() =>
|
|
46
|
+
import("mainstack-payments").then((mod) => mod.MainstackPaymentsProvider),
|
|
47
|
+
{
|
|
48
|
+
ssr: false,
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function MyApp({ Component, pageProps }: AppProps) {
|
|
53
|
+
return (
|
|
54
|
+
<ChakraProvider theme={theme}>
|
|
55
|
+
<MainstackPaymentsProvider>
|
|
56
|
+
</MainstackPaymentsProvider>
|
|
57
|
+
</ChakraProvider>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
32
62
|
The config object should contain the following properties:
|
|
33
63
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
* `amount*`: The amount for the product to be paid
|
|
65
|
+
|
|
66
|
+
* `accountId*`: The account ID of the user making the payment
|
|
67
|
+
|
|
68
|
+
* `currency*`: The currency to be used for the payment
|
|
69
|
+
|
|
70
|
+
* `reference*`: Uniquely generated identifier for this payment
|
|
71
|
+
|
|
72
|
+
* `transactionFeesSlug*`: The slug of the transaction fees to be applied to the payment usually determined by the backend, e.g 'store-pro-plan'
|
|
73
|
+
|
|
74
|
+
* `userAllowsWalletPayment*`: A boolean value that states if the merchant has allowed wallet payment
|
|
75
|
+
|
|
76
|
+
* `userAllowsCardPayment*`: A boolean value that states if the merchant has allowed card payment
|
|
77
|
+
|
|
78
|
+
* `metadata*`: An object that contains additional information about the payment. See more on this [here](#metadata)
|
|
79
|
+
|
|
80
|
+
* `baseUrl*`: The base URL of the legacy API. This API is what is used primarily to make payments. It is used initialise, charge and verify payment.
|
|
81
|
+
|
|
82
|
+
* `hasDiscountCode`: A optional boolean to show the discount code input. Default is false.
|
|
83
|
+
|
|
84
|
+
* `mainstackProductId`: A User's ID for a particular product, e.g store\_id, bookings\_id etc.
|
|
85
|
+
|
|
86
|
+
* `STRIPE_SECRET_KEY`: Stripe secret key for stripe payments, usually store in an env.
|
|
87
|
+
|
|
88
|
+
* `applyTrancheFee`: Boolean that is passed to the transaction fees endpoint and dictates if a tranch fee should be applied for transaction fees.This is specifically for Pay In Tranches payments. Default is false.
|
|
89
|
+
|
|
90
|
+
* `paymentOptions`: An array of payment options that should be enabled for the user can select from. The options are 'paystack', 'startbutton', 'wallet', 'stripe'
|
|
91
|
+
|
|
92
|
+
* `paystackRedirectUrl`: The URL to redirect to after a successful payment with Paystack or Startbutton. this is required if paystack or startbutton is enabled. More on this can be found [here](#paystackredirecturl)
|
|
93
|
+
|
|
94
|
+
* `customizations`: This is an object that takes values that adjust layout, styling or display of elements on the library. See full description [here](https://app.joggr.io/app/documents/b5b2ff2f-550d-4057-bed3-441870eaaf5d/edit#customizations).
|
|
47
95
|
|
|
48
96
|
#### metadata
|
|
49
97
|
|
|
50
98
|
The `metadata` object should contain the following properties:
|
|
51
99
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
100
|
+
* -`productName`: The name of the product being paid for
|
|
101
|
+
|
|
102
|
+
* -`type`: The type of product being paid for
|
|
103
|
+
|
|
104
|
+
* -`account_id`: The account ID of the user making the payment
|
|
105
|
+
|
|
106
|
+
* -`user_id`: The user ID of the user making the payment
|
|
107
|
+
|
|
108
|
+
* -`product_id`: The product ID of the product being paid for
|
|
109
|
+
|
|
110
|
+
* -`mainstack_product_type`: What Category of Mainstack Product is being paid for, accepted values are 'store', 'editor', 'bookings', 'mediakit', 'invoicing', 'hosted\_courses'
|
|
111
|
+
|
|
112
|
+
* `[key:string]` : Any other key-value pair that you want to add to the metadata object
|
|
113
|
+
|
|
114
|
+
#### Customizations
|
|
115
|
+
|
|
116
|
+
* `theme_color`: custom color the the Pay button
|
|
117
|
+
|
|
118
|
+
* `button_label`: custom label for the Pay button
|
|
119
|
+
|
|
120
|
+
* `font_family`: To set the font family for all the payment library texts and inputs
|
|
59
121
|
|
|
60
|
-
|
|
122
|
+
* `hideDetails`: Boolean that hide the summary details section of the payment library. Default is false.
|
|
123
|
+
|
|
124
|
+
* `hideBackButton` : Boolean to remove the back button that is next to the Pay button.
|
|
125
|
+
|
|
126
|
+
* `isSingleColumn` : This converts the payment library layout from 2 columns to a single column. Not that this happens by default on mobile screens.
|
|
127
|
+
|
|
128
|
+
* `padding` : This can be used to adjust the surrounding padding of the payment library.
|
|
129
|
+
|
|
130
|
+
* `showDefaultInputFields` This is an object used to determine what default input fields will be shown on the checkout form. They include:
|
|
131
|
+
|
|
132
|
+
* `email` : For the Email input. Default is true.
|
|
133
|
+
|
|
134
|
+
* `fullname`: For the Name input. Default is true.
|
|
135
|
+
|
|
136
|
+
* `phone`: For the PhoneNumber input. Default is false.
|
|
61
137
|
|
|
62
138
|
The `paystackRedirectUrl` is the URL to redirect to after a successful payment with Paystack or Startbutton. This page will be created by you and should contain the following code:
|
|
63
139
|
|
|
64
|
-
```
|
|
140
|
+
```typescript
|
|
65
141
|
import { useEffect } from "react";
|
|
66
142
|
|
|
67
143
|
const PostMessagePage = () => {
|
|
@@ -83,31 +159,37 @@ The aim of this is to send a postMessage to the iframe that loads Startbutton or
|
|
|
83
159
|
|
|
84
160
|
Other Props that can be passed to the `MainstackPayments` component are:
|
|
85
161
|
|
|
86
|
-
|
|
87
|
-
- `customForm`: This takes a ReactNode used to add a custom form to the payment page. This prop should also be used with `customFormValues`, which is an object with the initial values of the custom form, and `customFormValidation` which should contan an object with yup validation schema for the custom form. More on this can be found [here](#customform)
|
|
88
|
-
- `onPaymentComplete`: This is a callback function that is called when the payment is completed.
|
|
89
|
-
- `onGoBack`: This is a callback function that is called when the user clicks the back button on the payment page.
|
|
90
|
-
- `onInitializePayment`: This function is called just as the payment is about to be initialized and is useful for triggering any actions before the payment is initialized, like triggering your `formik.validateForm()` to validate the errors on your custom form and handle them accordingly.
|
|
162
|
+
* `summaryTitle`: This takes a string or ReactNode and is used to replace the title of the payment summary section, the default is always the Product name.
|
|
91
163
|
|
|
92
|
-
|
|
164
|
+
* `checkoutTitle`: This takes a string or ReactNode and is used to replace the title of the checkout form section, the default is always "**Checkout Details"**
|
|
93
165
|
|
|
94
|
-
|
|
166
|
+
* `customForm`: This takes a ReactNode used to add a custom form to the payment page.
|
|
95
167
|
|
|
96
|
-
|
|
97
|
-
import { useRef } from "react";
|
|
168
|
+
* `defaultFormValues`: This is an object with `fullname` and `email` keys. Their values are passed to their respective inputs as default values.
|
|
98
169
|
|
|
99
|
-
|
|
170
|
+
* `onPaymentComplete`: This is a callback function that is called when the payment is completed. It contains a payload that will include the amount, default input values, and reference of the payment, as well as some other optional data.
|
|
100
171
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
172
|
+
* `onGoBack`: This is a callback function that is called when the user clicks the back button on the payment page.
|
|
173
|
+
|
|
174
|
+
* `onInitializePayment`: This is an async function is called just as the payment is about to be initialized and is useful for triggering any actions before the payment is initialized, like validating your custom form or making an api call to validate something with the user's name or email before proceeding with payment. It contains an argument that has the values for the default form inputs, and must return a promise that resolves an object with a `terminate` boolean property. The payment initialization will terminate immediately the promise resolves depending on what the value of `terminate` is.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
<MainstackPayments
|
|
178
|
+
paymentConfig={config}
|
|
179
|
+
onGoBack={goBack}
|
|
180
|
+
onPaymentComplete={(e) => onPaymentSuccess(e)}
|
|
181
|
+
customForm={
|
|
182
|
+
<>{customForm}</>
|
|
183
|
+
}
|
|
184
|
+
onInitializePayment={onInitPayment}
|
|
185
|
+
/>
|
|
111
186
|
```
|
|
112
187
|
|
|
113
188
|
> Happy Hacking !!!
|
|
189
|
+
|
|
190
|
+
<!-- @joggr:editLink(b5b2ff2f-550d-4057-bed3-441870eaaf5d):start -->
|
|
191
|
+
---
|
|
192
|
+
<a href="https://app.joggr.io/app/documents/b5b2ff2f-550d-4057-bed3-441870eaaf5d/edit">
|
|
193
|
+
<img src="https://cdn.joggr.io/assets/static/badges/joggr-document-edit.svg?did=b5b2ff2f-550d-4057-bed3-441870eaaf5d" alt="Edit doc on Joggr" />
|
|
194
|
+
</a>
|
|
195
|
+
<!-- @joggr:editLink(b5b2ff2f-550d-4057-bed3-441870eaaf5d):end -->
|