payrex-node 1.7.0 → 1.7.2
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.7.2] - 2025-07-22
|
|
4
|
+
|
|
5
|
+
- Support cancel payment intent.
|
|
6
|
+
|
|
7
|
+
## [1.7.1] - 2025-07-11
|
|
8
|
+
|
|
9
|
+
- Support setup_future_usage on Billing Statement.
|
|
10
|
+
|
|
3
11
|
## [1.7.0] - 2025-06-24
|
|
4
12
|
|
|
5
13
|
- Return billingStatementMerchantName in Billing Statement resource.
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ function BillingStatementEntity(apiResource) {
|
|
|
16
16
|
this.livemode = data.livemode;
|
|
17
17
|
this.metadata = data.metadata;
|
|
18
18
|
this.paymentIntent = data.payment_intent;
|
|
19
|
+
this.setupFutureUsage = data.setup_future_usage;
|
|
19
20
|
this.statementDescriptor = data.statement_descriptor;
|
|
20
21
|
this.status = data.status;
|
|
21
22
|
this.paymentSettings = data.payment_settings;
|
|
@@ -6,6 +6,15 @@ function PaymentIntentService(client) {
|
|
|
6
6
|
this.path = 'payment_intents';
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
PaymentIntentService.prototype.cancel = function (id) {
|
|
10
|
+
return this.request({
|
|
11
|
+
path: `${this.path}/${id}/cancel`,
|
|
12
|
+
method: 'post',
|
|
13
|
+
}).then(function (response) {
|
|
14
|
+
return new PaymentIntentEntity(response);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
9
18
|
PaymentIntentService.prototype.capture = function (id, payload) {
|
|
10
19
|
return this.request({
|
|
11
20
|
path: `${this.path}/${id}/capture`,
|
package/test2.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const payrex = require('payrex-node')(
|
|
2
|
+
'sk_live_znE26cM4ZbZP3mfTLeZsnw7EceWHKiPN'
|
|
3
|
+
);
|
|
4
|
+
|
|
5
|
+
const RequestInvalidError = require('./src/errors/RequestInvalidError');
|
|
6
|
+
const AuthenticationInvalidError = require('./src/errors/AuthenticationInvalidError');
|
|
7
|
+
const ResourceNotFoundError = require('./src/errors/ResourceNotFoundError');
|
|
8
|
+
|
|
9
|
+
// try {
|
|
10
|
+
// const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 });
|
|
11
|
+
// } catch (error) {
|
|
12
|
+
// console.log('caught error!')
|
|
13
|
+
// if (error instanceof ResourceNotFoundError) {
|
|
14
|
+
// // handle error if a resource does not exist.
|
|
15
|
+
// } else if (error instanceof AuthenticationInvalidError) {
|
|
16
|
+
// // handle authentication error
|
|
17
|
+
// } else if (error instanceof RequestInvalidError) {
|
|
18
|
+
// console.log('handle error if there\'s validation error');
|
|
19
|
+
|
|
20
|
+
// error.errors.forEach((e) => {
|
|
21
|
+
// console.log(e.code);
|
|
22
|
+
// console.log(e.detail);
|
|
23
|
+
// });
|
|
24
|
+
// }
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
(async () => {
|
|
28
|
+
try {
|
|
29
|
+
const paymentIntent = await payrex.paymentIntents.create({ amount: 10000 });
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.log('caught error!');
|
|
32
|
+
console.log(error.name);
|
|
33
|
+
if (error.name === 'ResourceNotFoundError') {
|
|
34
|
+
// handle error if a resource does not exist.
|
|
35
|
+
} else if (error.name === 'AuthenticationInvalidError') {
|
|
36
|
+
// handle authentication error
|
|
37
|
+
} else if (error.name === 'RequestInvalidError') {
|
|
38
|
+
console.log("handle error if there's validation error");
|
|
39
|
+
|
|
40
|
+
error.errors.forEach((e) => {
|
|
41
|
+
console.log(e.code);
|
|
42
|
+
console.log(e.detail);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
|
|
48
|
+
const refund = await payrex.refunds.update(
|
|
49
|
+
're_xPy5nb7p6R7jG4ZPEJu5WvVCb8Lz31qx',
|
|
50
|
+
{
|
|
51
|
+
metadata: {
|
|
52
|
+
'some_key3': 'some_val3'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const billingStatement = await payrex.billingStatements.create(
|
|
58
|
+
{
|
|
59
|
+
currency: 'PHP',
|
|
60
|
+
customer_id: 'cus_BcArwt1hUhBB8HTdbsWxeDavsv5Jm37L',
|
|
61
|
+
payment_settings: {
|
|
62
|
+
payment_methods: [
|
|
63
|
+
'card'
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
setup_future_usage: 'on_session'
|
|
67
|
+
}
|
|
68
|
+
)
|