Skip to content

Commit 2dbcfec

Browse files
committed
[Components] ifthenpay #16383
Sources - New Payment Actions - Create Payment Reference - Issue Refund
1 parent 1578b90 commit 2dbcfec

File tree

7 files changed

+236
-227
lines changed

7 files changed

+236
-227
lines changed

components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs

Lines changed: 116 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,147 @@
1+
import { PAYMENT_METHOD_OPTIONS } from "../../common/constants.mjs";
12
import ifthenpay from "../../ifthenpay.app.mjs";
2-
import { axios } from "@pipedream/platform";
33

44
export default {
55
key: "ifthenpay-create-payment-reference",
66
name: "Create Payment Reference",
77
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",
99
type: "action",
1010
props: {
1111
ifthenpay,
1212
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,
1718
},
18-
amount: {
19+
mbKey: {
1920
propDefinition: [
2021
ifthenpay,
21-
"amount",
22+
"mbKey",
2223
],
24+
hidden: true,
2325
},
24-
customerDetails: {
26+
mbWayKey: {
2527
propDefinition: [
2628
ifthenpay,
27-
"customerDetails",
29+
"mbWayKey",
2830
],
31+
hidden: true,
2932
},
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)",
3547
optional: true,
48+
hidden: true,
3649
},
3750
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",
4260
optional: true,
61+
hidden: true,
4362
},
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 {};
44123
},
45124
async run({ $ }) {
46125
const response = await this.ifthenpay.generatePaymentReference({
126+
$,
47127
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+
},
52145
});
53146

54147
$.export("$summary", `Successfully created payment reference with Order ID: ${response.OrderId}`);
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
import ifthenpay from "../../ifthenpay.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "ifthenpay-issue-refund",
65
name: "Issue Refund",
76
description: "Issue a full or partial refund for a previously completed payment via Ifthenpay. [See the documentation](https://ifthenpay.com/docs/en/)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
ifthenpay,
12-
originalPaymentId: {
11+
requestId: {
1312
propDefinition: [
1413
ifthenpay,
15-
"originalPaymentId",
14+
"requestId",
1615
],
1716
},
18-
refundAmount: {
19-
propDefinition: [
20-
ifthenpay,
21-
"refundAmount",
22-
],
23-
},
24-
reasonForRefund: {
25-
propDefinition: [
26-
ifthenpay,
27-
"reasonForRefund",
28-
],
29-
optional: true,
17+
amount: {
18+
type: "string",
19+
label: "Amount",
20+
description: "The amount to be refunded.",
3021
},
3122
},
3223
async run({ $ }) {
3324
const response = await this.ifthenpay.refundPayment({
34-
originalPaymentId: this.originalPaymentId,
35-
refundAmount: this.refundAmount,
36-
reasonForRefund: this.reasonForRefund,
25+
$,
26+
data: {
27+
backofficekey: this.ifthenpay.$auth.backoffice_key,
28+
requestId: this.requestId,
29+
amount: this.amount,
30+
},
3731
});
3832

39-
$.export("$summary", `Successfully issued a refund for payment ID: ${this.originalPaymentId}`);
33+
$.export("$summary", `Successfully issued a refund for payment ID: ${this.requestId}`);
4034
return response;
4135
},
4236
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const PAYMENT_METHOD_OPTIONS = [
2+
"MB WAY",
3+
"Multibanco",
4+
];

0 commit comments

Comments
 (0)