mainstack-payments 0.0.0
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/.env.sample +1 -0
- package/.eslintignore +5 -0
- package/.eslintrc.json +95 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +15 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +6 -0
- package/.prettierignore +7 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +10 -0
- package/README.md +113 -0
- package/build/_redirects +1 -0
- package/build/mainstack-payments.js +97183 -0
- package/build/manifest.json +15 -0
- package/build/robots.txt +3 -0
- package/build/style.css +6 -0
- package/build/vite.svg +1 -0
- package/commitlint.config.cjs +1 -0
- package/index.html +31 -0
- package/package.json +86 -0
- package/public/_redirects +1 -0
- package/public/manifest.json +15 -0
- package/public/robots.txt +3 -0
- package/public/vite.svg +1 -0
- package/src/api/config.ts +36 -0
- package/src/api/index.ts +84 -0
- package/src/app.tsx +39 -0
- package/src/assets/images/tired-emoji.png +0 -0
- package/src/assets/styles/index.css +26 -0
- package/src/assets/themes/baseThemes.ts +30 -0
- package/src/components/CheckoutForm.tsx +426 -0
- package/src/components/DrawerModal.tsx +63 -0
- package/src/components/Payment.tsx +772 -0
- package/src/components/PaystackPaymentErrorModal.tsx +120 -0
- package/src/components/PaystackPaymentModal.tsx +120 -0
- package/src/components/WalletPay.tsx +160 -0
- package/src/constants/index.ts +3 -0
- package/src/enums/currenciesEnums.ts +7 -0
- package/src/hooks/usePayment.ts +60 -0
- package/src/index.ts +3 -0
- package/src/pages/Home.tsx +97 -0
- package/src/pages/Index.tsx +23 -0
- package/src/pages/Login.tsx +13 -0
- package/src/pages/Page404.tsx +13 -0
- package/src/pages/PaymentRedirect.tsx +15 -0
- package/src/routes/index.tsx +8 -0
- package/src/types/index.ts +48 -0
- package/src/utils/countries-flag.json +1752 -0
- package/src/utils/countries_flag.json +1502 -0
- package/src/utils/countries_with_flags_and_currencies.json +4004 -0
- package/src/utils/formatUnderscoreText.ts +5 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/stringifyPrice.ts +37 -0
- package/src/utils/validations.ts +44 -0
- package/tsconfig.json +35 -0
- package/vite.config.ts +36 -0
package/.env.sample
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
REACT_APP_BASE_URL=""
|
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"eslint:recommended",
|
|
4
|
+
"airbnb/hooks",
|
|
5
|
+
"airbnb-typescript",
|
|
6
|
+
"plugin:react/recommended",
|
|
7
|
+
"plugin:react/jsx-runtime",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
10
|
+
"prettier/prettier",
|
|
11
|
+
"prettier",
|
|
12
|
+
"plugin:prettier/recommended",
|
|
13
|
+
"plugin:import/recommended"
|
|
14
|
+
],
|
|
15
|
+
"plugins": [
|
|
16
|
+
"react-hooks",
|
|
17
|
+
"@typescript-eslint",
|
|
18
|
+
"prettier",
|
|
19
|
+
"react",
|
|
20
|
+
"import",
|
|
21
|
+
"jsx-a11y"
|
|
22
|
+
],
|
|
23
|
+
"parser": "@typescript-eslint/parser",
|
|
24
|
+
"parserOptions": {
|
|
25
|
+
"ecmaFeatures": {
|
|
26
|
+
"jsx": true
|
|
27
|
+
},
|
|
28
|
+
"ecmaVersion": "latest",
|
|
29
|
+
"sourceType": "module",
|
|
30
|
+
"tsconfigRootDir": ".",
|
|
31
|
+
"project": ["./tsconfig.json"]
|
|
32
|
+
},
|
|
33
|
+
"env": {
|
|
34
|
+
"browser": true,
|
|
35
|
+
"es6": true
|
|
36
|
+
},
|
|
37
|
+
"settings": {
|
|
38
|
+
"import/resolver": {
|
|
39
|
+
"typescript": {
|
|
40
|
+
"project": "./tsconfig.json"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"react": {
|
|
44
|
+
"version": "detect"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"rules": {
|
|
48
|
+
"no-var": 2,
|
|
49
|
+
"semi": 0,
|
|
50
|
+
"func-names": 0,
|
|
51
|
+
"default-param-last": 0,
|
|
52
|
+
"camelcase": 0,
|
|
53
|
+
"consistent-return": 0,
|
|
54
|
+
"no-console": 1,
|
|
55
|
+
"no-unused-expressions": 0,
|
|
56
|
+
"no-plusplus": 0,
|
|
57
|
+
"no-underscore-dangle": 0,
|
|
58
|
+
"no-nested-ternary": 0,
|
|
59
|
+
"object-shorthand": 0,
|
|
60
|
+
"class-methods-use-this": 0,
|
|
61
|
+
"import/extensions": 0,
|
|
62
|
+
"import/no-unresolved": 0,
|
|
63
|
+
"jsx-a11y/label-has-associated-control": 0,
|
|
64
|
+
"jsx-a11y/no-autofocus": 0,
|
|
65
|
+
"max-classes-per-file": 0,
|
|
66
|
+
"import/prefer-default-export": 0,
|
|
67
|
+
"import/no-extraneous-dependencies": 0,
|
|
68
|
+
"no-param-reassign": 0,
|
|
69
|
+
"no-prototype-builtins": 0,
|
|
70
|
+
"no-unsafe-optional-chaining": 0,
|
|
71
|
+
"radix": 0,
|
|
72
|
+
"react/prop-types": 0,
|
|
73
|
+
"react-hooks/rules-of-hooks": 2,
|
|
74
|
+
"react-hooks/exhaustive-deps": 0,
|
|
75
|
+
"react/no-children-prop": 0,
|
|
76
|
+
"react/jsx-key": 0,
|
|
77
|
+
"react/display-name": 0,
|
|
78
|
+
"react/react-in-jsx-scope": 0,
|
|
79
|
+
"react/no-unescaped-entities": 0,
|
|
80
|
+
"@typescript-eslint/no-empty-function": 0,
|
|
81
|
+
"@typescript-eslint/no-unsafe-assignment": 0,
|
|
82
|
+
"@typescript-eslint/restrict-template-expressions": 0,
|
|
83
|
+
"@typescript-eslint/no-unsafe-argument": 0,
|
|
84
|
+
"@typescript-eslint/no-unsafe-call": 0,
|
|
85
|
+
"@typescript-eslint/no-unsafe-member-access": 0,
|
|
86
|
+
"@typescript-eslint/ban-ts-comment": 0,
|
|
87
|
+
"@typescript-eslint/no-explicit-any": 0,
|
|
88
|
+
"@typescript-eslint/no-floating-promises": 0,
|
|
89
|
+
"@typescript-eslint/no-unsafe-return": 0,
|
|
90
|
+
"prefer-const": 1,
|
|
91
|
+
"@typescript-eslint/no-misused-promises": 0,
|
|
92
|
+
"@typescript-eslint/no-unused-vars": 1,
|
|
93
|
+
"no-sparse-arrays": 0
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
### Subject / Header
|
|
2
|
+
|
|
3
|
+
State the subject or header of the PR e.g Setting Up Code Base
|
|
4
|
+
|
|
5
|
+
### What changed?
|
|
6
|
+
|
|
7
|
+
Here state the over view of what changed. Also inculde if a command is needed to be ran after pulling. This is an example
|
|
8
|
+
|
|
9
|
+
- Setting up the code base for frontend dashboard
|
|
10
|
+
- Added Pull Pequest template and other file template
|
|
11
|
+
- New package are added, thus the need to run `yarn install`.
|
|
12
|
+
|
|
13
|
+
### Whats Remaining
|
|
14
|
+
|
|
15
|
+
Here state if anything is missing that should be in the PR but its not, this so that the person reviewing the code would know whats missing and can test better
|
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!-- @format -->
|
|
2
|
+
|
|
3
|
+
# Mainstack Payments
|
|
4
|
+
|
|
5
|
+
This is a documentation of how the Mainstack Payments library works, and how to use it in your project.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
To install the Mainstack Payments library, you need to run the following command in your terminal:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add mainstack-payments
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
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
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
import { MainstackPayments } from "mainstack-payments";
|
|
21
|
+
|
|
22
|
+
export default function Home() {
|
|
23
|
+
const config = {};
|
|
24
|
+
return (
|
|
25
|
+
<Box>
|
|
26
|
+
<MainstackPayment paymentConfig={config} />
|
|
27
|
+
</Box>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The config object should contain the following properties:
|
|
33
|
+
|
|
34
|
+
- `amount*`: The amount for the product to be paid
|
|
35
|
+
- `accountId*`: The account ID of the user making the payment
|
|
36
|
+
- `currency*`: The currency to be used for the payment
|
|
37
|
+
- `reference*`: Uniquely generated identifier for this payment
|
|
38
|
+
- `transactionFeesSlug*`: The slug of the transaction fees to be applied to the payment usually determined by the backend, e.g 'store-pro-plan'
|
|
39
|
+
- `userAllowsWalletPayment*`: A boolean value that states if the merchant has allowed wallet payment
|
|
40
|
+
- `userAllowsCardPayment*`: A boolean value that states if the merchant has allowed card payment
|
|
41
|
+
- `metadata*`: An object that contains additional information about the payment. See more on this [here](#metadata)
|
|
42
|
+
- `baseUrl*`: The base URL of the legacy API. This API is what is used primarily to make payments. It is used initialize, chrage and verify payment.
|
|
43
|
+
- `authMSUrl*`: The base URL of the Mainstack Auth API. This API is used to get transaction fees based on the user's settings.
|
|
44
|
+
- `paymentOptions`: An array of payment options that should be enabled for the user can select from. The options are 'paystack', 'startbutton', 'wallet', 'stripe'
|
|
45
|
+
- `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)
|
|
46
|
+
- `customizations`: This is an object that takes values for `theme_color` for the Pay button, `button_label` and `font_family` for the whole Payment page.
|
|
47
|
+
|
|
48
|
+
#### metadata
|
|
49
|
+
|
|
50
|
+
The `metadata` object should contain the following properties:
|
|
51
|
+
|
|
52
|
+
- -`productName`: The name of the product being paid for
|
|
53
|
+
- -`type`: The type of product being paid for
|
|
54
|
+
- -`account_id`: The account ID of the user making the payment
|
|
55
|
+
- -`user_id`: The user ID of the user making the payment
|
|
56
|
+
- -`product_id`: The product ID of the product being paid for
|
|
57
|
+
- -`mainstack_product_type`: What Category of Mainsatck Product is being paid for, accepted values are 'store', 'editor', 'bookings', 'mediakit', 'invoicing', 'hosted_courses'
|
|
58
|
+
- `[key:string]` : Any other key-value pair that you want to add to the metadata object
|
|
59
|
+
|
|
60
|
+
#### paystackRedirectUrl
|
|
61
|
+
|
|
62
|
+
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
|
+
|
|
64
|
+
```jsx
|
|
65
|
+
import { useEffect } from "react";
|
|
66
|
+
|
|
67
|
+
const PostMessagePage = () => {
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
(() => {
|
|
70
|
+
window.parent.postMessage({ type: "Payment Completed" }, "*");
|
|
71
|
+
})();
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
return <div></div>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default PostMessagePage;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The aim of this is to send a postMessage to the iframe that loads Startbutton or Paystack to let them know that payment is complete and they can close the iframe and verify the payment.
|
|
81
|
+
|
|
82
|
+
## Extra Props
|
|
83
|
+
|
|
84
|
+
Other Props that can be passed to the `MainstackPayments` component are:
|
|
85
|
+
|
|
86
|
+
- `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.
|
|
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.
|
|
91
|
+
|
|
92
|
+
#### customForm
|
|
93
|
+
|
|
94
|
+
In order to update the formik values for your custom form, you can add a `ref` to the `MainstackPayments` component and call the `updateCustomFormValues` method on the ref with the new values in your onChange handler. The `updateCustomFormValues` method takes 2 arguments, the first is a string of the formik value you want to update and the second is the value you want to update it with.
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
import { useRef } from "react";
|
|
98
|
+
|
|
99
|
+
const ref = useRef(null);
|
|
100
|
+
|
|
101
|
+
const handleChange = (e) => {
|
|
102
|
+
ref.current.updateCustomFormValues("name", e.target.value);
|
|
103
|
+
};
|
|
104
|
+
<MainstackPayments
|
|
105
|
+
ref={ref}
|
|
106
|
+
customForm={CustomForm}
|
|
107
|
+
customFormValues={{ name: "John Doe" }}
|
|
108
|
+
customFormValidation={customFormValidation}
|
|
109
|
+
onChange={handleChange}
|
|
110
|
+
/>;
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
> Happy Hacking !!!
|
package/build/_redirects
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/* /index.html 200
|