|
| 1 | +import { PAYMENT_METHOD_OPTIONS } from "../../common/constants.mjs"; |
1 | 2 | import ifthenpay from "../../ifthenpay.app.mjs"; |
2 | | -import { axios } from "@pipedream/platform"; |
3 | 3 |
|
4 | 4 | export default { |
5 | 5 | key: "ifthenpay-create-payment-reference", |
6 | 6 | name: "Create Payment Reference", |
7 | 7 | description: "Generates a Multibanco or MB WAY payment reference with a specified amount, entity code, and deadline. [See the documentation](https://ifthenpay.com/docs/en/)", |
8 | | - version: "0.0.{{ts}}", |
| 8 | + version: "0.0.1", |
9 | 9 | type: "action", |
10 | 10 | props: { |
11 | 11 | ifthenpay, |
12 | 12 | paymentMethod: { |
13 | | - propDefinition: [ |
14 | | - ifthenpay, |
15 | | - "paymentMethod", |
16 | | - ], |
| 13 | + type: "string", |
| 14 | + label: "Payment Method", |
| 15 | + description: "The payment method to use for Ifthenpay (e.g., MB WAY, Multibanco)", |
| 16 | + options: PAYMENT_METHOD_OPTIONS, |
| 17 | + reloadProps: true, |
17 | 18 | }, |
18 | | - amount: { |
| 19 | + mbKey: { |
19 | 20 | propDefinition: [ |
20 | 21 | ifthenpay, |
21 | | - "amount", |
| 22 | + "mbKey", |
22 | 23 | ], |
| 24 | + hidden: true, |
23 | 25 | }, |
24 | | - customerDetails: { |
| 26 | + mbWayKey: { |
25 | 27 | propDefinition: [ |
26 | 28 | ifthenpay, |
27 | | - "customerDetails", |
| 29 | + "mbWayKey", |
28 | 30 | ], |
| 31 | + hidden: true, |
29 | 32 | }, |
30 | | - expirationDate: { |
31 | | - propDefinition: [ |
32 | | - ifthenpay, |
33 | | - "expirationDate", |
34 | | - ], |
| 33 | + orderId: { |
| 34 | + type: "string", |
| 35 | + label: "Order Id", |
| 36 | + description: "Payment identifier defined by the client (e.g., invoice number, order number, etc.)", |
| 37 | + }, |
| 38 | + amount: { |
| 39 | + type: "string", |
| 40 | + label: "Amount", |
| 41 | + description: "The amount to be paid with decimal separator \".\"", |
| 42 | + }, |
| 43 | + mobileNumber: { |
| 44 | + type: "string", |
| 45 | + label: "Mobile Number", |
| 46 | + description: "Place the country code before the mobile number without any spaces (use '#'' to separate the country code from the mobile number - p.e. 351#912345678)", |
35 | 47 | optional: true, |
| 48 | + hidden: true, |
36 | 49 | }, |
37 | 50 | description: { |
38 | | - propDefinition: [ |
39 | | - ifthenpay, |
40 | | - "description", |
41 | | - ], |
| 51 | + type: "string", |
| 52 | + label: "Description", |
| 53 | + description: "Description of the payment, with a maximum length of 200 characters", |
| 54 | + optional: true, |
| 55 | + }, |
| 56 | + url: { |
| 57 | + type: "string", |
| 58 | + label: "URL", |
| 59 | + description: "URL address, with a maximum length of 200 characters", |
42 | 60 | optional: true, |
| 61 | + hidden: true, |
43 | 62 | }, |
| 63 | + clientCode: { |
| 64 | + type: "string", |
| 65 | + label: "Client Code", |
| 66 | + description: "Client's code, with a maximum length of 200 characters", |
| 67 | + optional: true, |
| 68 | + hidden: true, |
| 69 | + }, |
| 70 | + clientName: { |
| 71 | + type: "string", |
| 72 | + label: "Client Name", |
| 73 | + description: "Client's name, with a maximum length of 200 characters", |
| 74 | + optional: true, |
| 75 | + hidden: true, |
| 76 | + }, |
| 77 | + email: { |
| 78 | + type: "string", |
| 79 | + label: "Email", |
| 80 | + description: "The Client's name.", |
| 81 | + optional: true, |
| 82 | + }, |
| 83 | + clientUsername: { |
| 84 | + type: "string", |
| 85 | + label: "Client Username", |
| 86 | + description: "Client's username, with a maximum length of 200 characters", |
| 87 | + optional: true, |
| 88 | + hidden: true, |
| 89 | + }, |
| 90 | + clientPhone: { |
| 91 | + type: "string", |
| 92 | + label: "Client Phone", |
| 93 | + description: "Client's cell phone or phone number, with a maximum length of 200 characters", |
| 94 | + optional: true, |
| 95 | + hidden: true, |
| 96 | + }, |
| 97 | + expiryDays: { |
| 98 | + type: "integer", |
| 99 | + label: "Expiry Days", |
| 100 | + description: "How many days the payment reference is valid for. [See the documentation](https://ifthenpay.com/docs/en/api/multibanco/#tag/multibanco/POST/init) for further details.", |
| 101 | + optional: true, |
| 102 | + hidden: true, |
| 103 | + }, |
| 104 | + }, |
| 105 | + async additionalProps(props) { |
| 106 | + const isMb = this.paymentMethod === "Multibanco"; |
| 107 | + |
| 108 | + props.mbKey.default = this.ifthenpay.$auth.mb_key; |
| 109 | + props.mbKey.hidden = !isMb; |
| 110 | + |
| 111 | + props.mbWayKey.default = this.ifthenpay.$auth.mbway_key; |
| 112 | + props.mbWayKey.hidden = isMb; |
| 113 | + props.mobileNumber.hidden = isMb; |
| 114 | + props.url.hidden = isMb; |
| 115 | + props.clientCode.hidden = isMb; |
| 116 | + props.clientName.hidden = isMb; |
| 117 | + props.email.label = "Client Email"; |
| 118 | + props.email.description = "Client's email address, with a maximum length of 200 characters"; |
| 119 | + props.clientUsername.hidden = isMb; |
| 120 | + props.clientPhone.hidden = isMb; |
| 121 | + props.expiryDays.hidden = isMb; |
| 122 | + return {}; |
44 | 123 | }, |
45 | 124 | async run({ $ }) { |
46 | 125 | const response = await this.ifthenpay.generatePaymentReference({ |
| 126 | + $, |
47 | 127 | paymentMethod: this.paymentMethod, |
48 | | - amount: this.amount, |
49 | | - customerDetails: this.customerDetails, |
50 | | - expirationDate: this.expirationDate, |
51 | | - description: this.description, |
| 128 | + data: { |
| 129 | + mbKey: this.mbKey, |
| 130 | + mbWayKey: this.mbWayKey, |
| 131 | + orderId: this.orderId, |
| 132 | + amount: parseFloat(this.amount), |
| 133 | + mobileNumber: this.mobileNumber, |
| 134 | + email: this.email, |
| 135 | + description: this.description, |
| 136 | + url: this.url, |
| 137 | + clientCode: this.clientCode, |
| 138 | + clientName: this.clientName, |
| 139 | + clientUsername: this.clientUsername, |
| 140 | + clientPhone: this.clientPhone, |
| 141 | + expiryDays: this.expiryDays, |
| 142 | + expirationDate: this.expirationDate, |
| 143 | + clientEmail: this.email, |
| 144 | + }, |
52 | 145 | }); |
53 | 146 |
|
54 | 147 | $.export("$summary", `Successfully created payment reference with Order ID: ${response.OrderId}`); |
|
0 commit comments