|
1 | 1 | # @lucadiba/satispay-client |
2 | 2 |
|
| 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 | + |
3 | 97 | ## 0.1.6 |
4 | 98 |
|
5 | 99 | ### Patch Changes |
|
0 commit comments