@pay-com/js 1.1.0 → 1.1.3
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/LICENSE +21 -0
- package/README.md +105 -0
- package/lib/index.d.ts +2 -0
- package/package.json +11 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Pay.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<h1 align="center">Pay Components JS Package</h1>
|
|
2
|
+
|
|
3
|
+
Pay Components are ready-to-use PCI DSS compliant payment fields you can embed into your checkout page through simple code. Your branding and styling remain untouched, and you don't have to worry about storing card data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To include Pay Components in your project, either install it using `npm i @pay-com/js`, or use our CDN:
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<script type="text/javascript" src="https://js.pay.com/v1"></script>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Get Started
|
|
14
|
+
|
|
15
|
+
### Initialize Pay
|
|
16
|
+
|
|
17
|
+
To initialize Pay, call `Pay.com()` with your unique merchant id:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const pay = await Pay.com({ identifier: 'merchant_id' })
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Initialize checkout object
|
|
24
|
+
|
|
25
|
+
In order to be able to start accepting payments, intialize the checkout object:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const checkout = pay.checkout({
|
|
29
|
+
clientSecret: 'payment_session_client_secret',
|
|
30
|
+
onSuccess: payment => {
|
|
31
|
+
// Can be used instead of checkout event listeners
|
|
32
|
+
},
|
|
33
|
+
onFailure: error => {
|
|
34
|
+
// Can be used instead of checkout event listeners
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You now have a checkout object with which you can render a payment form, validate it, and subscribe to events.
|
|
40
|
+
|
|
41
|
+
To subscribe to different events, use the `checkout.on` function:
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
checkout.on(checkout.EVENT_TYPES.PAYMENT_SUCCESS, payment => {
|
|
45
|
+
// Do something on success
|
|
46
|
+
})
|
|
47
|
+
checkout.on(checkout.EVENT_TYPES.PAYMENT_PROCESSING, () => {
|
|
48
|
+
// Do something on payment processing
|
|
49
|
+
})
|
|
50
|
+
checkout.on(checkout.EVENT_TYPES.PAYMENT_FAILURE, error => {
|
|
51
|
+
// Do something on error
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Render Payment Form
|
|
56
|
+
|
|
57
|
+
In order to render a payment form, create an empty div which the form will be rendered in, e.g.:
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<div id="paycom_checkout"></div>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Once you have the div, call the `render` function:
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
checkout.universal({
|
|
67
|
+
container: '#paycom_checkout'
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Thats it! You are now ready to securely accept payments in your website.
|
|
72
|
+
|
|
73
|
+
### Manual validation and submission
|
|
74
|
+
|
|
75
|
+
If you wish to render the fields without a submission button for more control, you have to pass the `submitButton: false` option to the `toggles` key under the `universal` function:
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
checkout.universal({
|
|
79
|
+
container: '#paycom_checkout',
|
|
80
|
+
toggles: {
|
|
81
|
+
submitButton: false
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Now the form will render without a button. To validate & submit the form, first create a button:
|
|
87
|
+
|
|
88
|
+
```html
|
|
89
|
+
<button id="pay_button">Pay now!</button>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then, create a click listener on the button:
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
document.getElementById('pay_button').addEventListener('click', async () => {
|
|
96
|
+
// Validate all fields before submitting
|
|
97
|
+
const { valid } = checkout.validate()
|
|
98
|
+
|
|
99
|
+
// If the payment form is valid, continue with the payment
|
|
100
|
+
if (valid) {
|
|
101
|
+
// Can also get the payment from return value of submit function.
|
|
102
|
+
const payment = await checkout.submit()
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
```
|
package/lib/index.d.ts
CHANGED
|
@@ -302,6 +302,8 @@ type ValidateFn = (frameType?: ELEMENT_TYPES) => Promise<FormattedErrors | void>
|
|
|
302
302
|
type ResetFn = (frameType?: ELEMENT_TYPES) => Promise<void>
|
|
303
303
|
|
|
304
304
|
type UpdateTransactionDetailsOpts = {
|
|
305
|
+
successUrl?: string
|
|
306
|
+
failureUrl?: string
|
|
305
307
|
consumer?: {
|
|
306
308
|
firstName?: string
|
|
307
309
|
lastName?: string
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pay-com/js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "",
|
|
5
|
-
"keywords": [
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"payments"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Pay.com",
|
|
8
10
|
"main": "lib/index.js",
|
|
9
11
|
"module": "lib/index.esm.js",
|
|
10
12
|
"types": "lib/index.d.ts",
|
|
11
13
|
"publishConfig": {
|
|
12
14
|
"registry": "https://registry.npmjs.org/"
|
|
13
15
|
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/pay-com/js.git"
|
|
19
|
+
},
|
|
14
20
|
"files": [
|
|
15
21
|
"lib/*.js",
|
|
16
22
|
"lib/*.d.ts"
|
|
@@ -30,7 +36,7 @@
|
|
|
30
36
|
"rollup-plugin-copy": "^3.4.0",
|
|
31
37
|
"rollup-plugin-dts": "^4.0.0",
|
|
32
38
|
"rollup-plugin-node-builtins": "^2.1.2",
|
|
33
|
-
"rollup-plugin-
|
|
39
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
34
40
|
"rollup-plugin-terser": "^7.0.2",
|
|
35
41
|
"rollup-plugin-typescript2": "^0.34.1",
|
|
36
42
|
"typescript": "^4.4.4"
|