Skip to content

Commit 81b7b6f

Browse files
authored
Merge pull request #53 from LucaDiba/changeset-release/main
Version Packages
2 parents 0b892be + f05261b commit 81b7b6f

File tree

3 files changed

+95
-94
lines changed

3 files changed

+95
-94
lines changed

.changeset/new-rocks-sing.md

Lines changed: 0 additions & 93 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,99 @@
11
# @lucadiba/satispay-client
22

3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- d66664d: # Breaking changes
8+
9+
## Errors
10+
11+
Before this change, the library returned the following object for all the Client requests:
12+
13+
```typescript
14+
const paymentResponse = await satispay.payments.create({
15+
flow: "MATCH_CODE",
16+
amountUnit: 100,
17+
currency: "EUR",
18+
});
19+
20+
/**
21+
* paymentResponse: {
22+
* success: true,
23+
* data: {
24+
* ...
25+
* }
26+
* } | {
27+
* success: false,
28+
* error: {
29+
* ...
30+
* }
31+
* }
32+
*/
33+
34+
if (paymentResponse.success) {
35+
const payment = paymentResponse.data;
36+
37+
// Save the payment id
38+
const paymentId = payment.id;
39+
40+
// Redirect the user to the redirectUrl
41+
const redirectUrl = payment.redirect_url;
42+
43+
// ...
44+
} else {
45+
// Handle the error
46+
const error = paymentResponse.error;
47+
}
48+
```
49+
50+
After this change, the library will directly throw an error if the request fails.
51+
If the request is successful, the library will return the successful response.
52+
53+
```typescript
54+
try {
55+
const payment = await satispay.payments.create({
56+
flow: "MATCH_CODE",
57+
amountUnit: 100,
58+
currency: "EUR",
59+
});
60+
61+
// Save the payment id
62+
const paymentId = payment.id;
63+
64+
// Redirect the user to the redirectUrl
65+
const redirectUrl = payment.redirect_url;
66+
67+
// ...
68+
} catch (error) {
69+
// Handle the error
70+
}
71+
```
72+
73+
The error type `SatispayError` has been introduced. It extends the `Error` class and has the following properties:
74+
75+
- `name: string` - The error name
76+
- `message: string` - The error message
77+
- `code: string` - The error code
78+
- `status: number` - The HTTP status code
79+
80+
It is possible to check the error type using the `isSatispayError` utility function.
81+
If the result is true, the error type `SatispayError` is automatically inferred.
82+
83+
```typescript
84+
import { SatispayError } from "@lucadiba/satispay-client";
85+
86+
try {
87+
// ...
88+
} catch (error) {
89+
if (SatispayError.isSatispayError(error)) {
90+
// The SatispayError type is automatically inferred to the error variable
91+
} else {
92+
// The type of the error variable is unknown
93+
}
94+
}
95+
```
96+
397
## 0.1.6
498

599
### Patch Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@lucadiba/satispay-client",
33
"license": "MIT",
4-
"version": "0.1.6",
4+
"version": "1.0.0",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
77
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)