@smartsoft001/revolut 2.116.0 → 2.118.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/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  `npm i @smartsoft001/revolut`
8
8
 
9
+ Supported Revolut Merchant API version: **`2024-09-01`**.
10
+
9
11
  ## 🛠️ Services & Methods
10
12
 
11
13
  ### PaypalService
package/index.js CHANGED
@@ -16,6 +16,7 @@ var RevolutConfig = class {
16
16
  test;
17
17
  token;
18
18
  };
19
+ var REVOLUT_API_VERSION = "2024-09-01";
19
20
  var REVOLUT_CONFIG_PROVIDER = "REVOLUT_CONFIG_PROVIDER";
20
21
  var IRevolutConfigProvider = class {
21
22
  };
@@ -32,34 +33,36 @@ var RevolutService = class {
32
33
  const config = await this.getConfig(obj.data);
33
34
  const data = {
34
35
  amount: obj.amount,
36
+ currency: "PLN",
35
37
  description: obj.name,
36
- capture_mode: "AUTOMATIC",
37
- merchant_order_ext_ref: obj.id,
38
- customer_email: obj.email,
39
- currency: "PLN"
38
+ capture_mode: "automatic",
39
+ merchant_order_ext_ref: obj.id
40
40
  };
41
- const response = await this.httpService.post(this.getBaseUrl(config) + "/api/1.0/orders", data, {
42
- headers: {
43
- "Content-Type": "application/json",
44
- Authorization: "Bearer " + config.token
45
- },
41
+ const hasCustomer = !!obj.email || !!obj.firstName || !!obj.lastName || !!obj.contactPhone;
42
+ if (hasCustomer) {
43
+ const fullName = [obj.firstName, obj.lastName].filter(Boolean).join(" ");
44
+ data.customer = {
45
+ email: obj.email,
46
+ full_name: fullName || void 0,
47
+ phone: obj.contactPhone
48
+ };
49
+ }
50
+ const response = await this.httpService.post(this.getBaseUrl(config) + "/api/orders", data, {
51
+ headers: this.getHeaders(config),
46
52
  maxRedirects: 0
47
53
  }).toPromise();
48
54
  return {
49
55
  responseData: response.data,
50
- orderId: response.data["public_id"]
56
+ orderId: response.data.token
51
57
  };
52
58
  }
53
59
  async getStatus(trans) {
54
60
  const config = await this.getConfig(trans.data);
55
61
  const historyItem = trans.history.find((h) => h.status === "started");
56
62
  const response = await this.httpService.get(
57
- this.getBaseUrl(config) + "/api/1.0/orders/" + historyItem.data.responseData.id,
63
+ this.getBaseUrl(config) + "/api/orders/" + historyItem.data.responseData.id,
58
64
  {
59
- headers: {
60
- "Content-Type": "application/json",
61
- Authorization: "Bearer " + config.token
62
- },
65
+ headers: this.getHeaders(config),
63
66
  maxRedirects: 0
64
67
  }
65
68
  ).toPromise();
@@ -74,7 +77,15 @@ var RevolutService = class {
74
77
  getBaseUrl(config) {
75
78
  if (config.test)
76
79
  return "https://sandbox-merchant.revolut.com";
77
- return "https://merchant.revolut.com/api";
80
+ return "https://merchant.revolut.com";
81
+ }
82
+ getHeaders(config) {
83
+ return {
84
+ "Content-Type": "application/json",
85
+ Accept: "application/json",
86
+ Authorization: "Bearer " + config.token,
87
+ "Revolut-Api-Version": REVOLUT_API_VERSION
88
+ };
78
89
  }
79
90
  async getConfig(data) {
80
91
  try {
@@ -90,14 +101,18 @@ var RevolutService = class {
90
101
  }
91
102
  getStatusFromExternal(status) {
92
103
  switch (status) {
93
- case "PROCESSING":
104
+ case "pending":
105
+ return "pending";
106
+ case "processing":
107
+ return "pending";
108
+ case "authorised":
94
109
  return "completed";
95
- case "CANCELLED":
110
+ case "completed":
111
+ return "completed";
112
+ case "cancelled":
96
113
  return "canceled";
97
- case "FAILED":
114
+ case "failed":
98
115
  return "canceled";
99
- case "PENDING":
100
- return "pending";
101
116
  default:
102
117
  return status;
103
118
  }
@@ -109,6 +124,7 @@ RevolutService = __decorateClass([
109
124
  ], RevolutService);
110
125
  export {
111
126
  IRevolutConfigProvider,
127
+ REVOLUT_API_VERSION,
112
128
  REVOLUT_CONFIG_PROVIDER,
113
129
  RevolutConfig,
114
130
  RevolutService
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartsoft001/revolut",
3
- "version": "2.116.0",
3
+ "version": "2.118.0",
4
4
  "description": "Utils for revolut",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,6 +2,7 @@ export declare class RevolutConfig {
2
2
  test?: boolean;
3
3
  token: string;
4
4
  }
5
+ export declare const REVOLUT_API_VERSION = "2024-09-01";
5
6
  export declare const REVOLUT_CONFIG_PROVIDER = "REVOLUT_CONFIG_PROVIDER";
6
7
  export declare abstract class IRevolutConfigProvider {
7
8
  abstract get(data: any): Promise<RevolutConfig>;
@@ -27,6 +27,7 @@ export declare class RevolutService implements ITransPaymentSingleService {
27
27
  }>;
28
28
  refund(trans: Trans<any>, comment: string): Promise<any>;
29
29
  private getBaseUrl;
30
+ private getHeaders;
30
31
  private getConfig;
31
32
  private getStatusFromExternal;
32
33
  }