Skip to content

Commit 60b76f8

Browse files
committed
Adyen: new action components
1 parent 49771c3 commit 60b76f8

File tree

8 files changed

+401
-7
lines changed

8 files changed

+401
-7
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import app from "../../adyen.app.mjs";
2+
3+
export default {
4+
key: "adyen-cancel-payment",
5+
name: "Cancel Payment",
6+
description: "Cancels a payment that has not yet been captured. [See the documentation](https://docs.adyen.com/api-explorer/checkout/71/post/payments/(paymentpspreference)/cancels)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
paymentPspReference: {
12+
propDefinition: [
13+
app,
14+
"paymentPspReference",
15+
],
16+
},
17+
merchantAccount: {
18+
propDefinition: [
19+
app,
20+
"merchantAccount",
21+
],
22+
},
23+
},
24+
methods: {
25+
cancelPayment({
26+
paymentPspReference, data,
27+
} = {}) {
28+
return this.app.getCheckoutAPI()
29+
.ModificationsApi
30+
.cancelAuthorisedPaymentByPspReference(paymentPspReference, data);
31+
},
32+
},
33+
async run({ $ }) {
34+
const {
35+
cancelPayment,
36+
paymentPspReference,
37+
merchantAccount,
38+
} = this;
39+
40+
const response = await cancelPayment({
41+
paymentPspReference,
42+
data: {
43+
merchantAccount,
44+
},
45+
});
46+
$.export("$summary", "Successfully cancelled payment.");
47+
return response;
48+
},
49+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import app from "../../adyen.app.mjs";
2+
3+
export default {
4+
key: "adyen-capture-payment",
5+
name: "Capture Payment",
6+
description: "Captures an authorized payment. This is typically used for delayed capture scenarios, such as when you need to verify the order before capturing the funds.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
paymentPspReference: {
12+
propDefinition: [
13+
app,
14+
"paymentPspReference",
15+
],
16+
},
17+
merchantAccount: {
18+
propDefinition: [
19+
app,
20+
"merchantAccount",
21+
],
22+
},
23+
amountCurrency: {
24+
propDefinition: [
25+
app,
26+
"amountCurrency",
27+
],
28+
},
29+
amountValue: {
30+
propDefinition: [
31+
app,
32+
"amountValue",
33+
],
34+
},
35+
},
36+
methods: {
37+
capturePayment({
38+
paymentPspReference, data,
39+
} = {}) {
40+
return this.app.getCheckoutAPI()
41+
.ModificationsApi
42+
.captureAuthorisedPayment(paymentPspReference, data);
43+
},
44+
},
45+
async run({ $ }) {
46+
const {
47+
capturePayment,
48+
paymentPspReference,
49+
merchantAccount,
50+
amountCurrency,
51+
amountValue,
52+
} = this;
53+
54+
const response = await capturePayment({
55+
paymentPspReference,
56+
data: {
57+
merchantAccount,
58+
amount: {
59+
currency: amountCurrency,
60+
value: amountValue,
61+
},
62+
},
63+
});
64+
65+
$.export("$summary", "Successfully captured payment.");
66+
return response;
67+
},
68+
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import app from "../../adyen.app.mjs";
2+
3+
export default {
4+
key: "adyen-create-payment",
5+
name: "Create Payment",
6+
description: "Creates a payment for a shopper. [See the documentation](https://docs.adyen.com/api-explorer/Checkout/71/post/payments)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
merchantAccount: {
12+
propDefinition: [
13+
app,
14+
"merchantAccount",
15+
],
16+
},
17+
amountCurrency: {
18+
propDefinition: [
19+
app,
20+
"amountCurrency",
21+
],
22+
},
23+
amountValue: {
24+
propDefinition: [
25+
app,
26+
"amountValue",
27+
],
28+
},
29+
reference: {
30+
type: "string",
31+
label: "Reference",
32+
description: "The reference to uniquely identify a payment. This reference is used in all communication with you about the payment status. We recommend using a unique value per payment; however, it is not a requirement. If you need to provide multiple references for a transaction, separate them with hyphens (`-`). Maximum length: 80 characters.",
33+
},
34+
returnUrl: {
35+
type: "string",
36+
label: "Return URL",
37+
description: "The URL to return to in case of a redirection. The format depends on the channel. For more information refer the the [documentation](https://docs.adyen.com/api-explorer/Checkout/71/post/payments#request-returnUrl).",
38+
},
39+
paymentMethodType: {
40+
propDefinition: [
41+
app,
42+
"paymentMethodType",
43+
({ merchantAccount }) => ({
44+
merchantAccount,
45+
}),
46+
],
47+
},
48+
paymentMethodDetails: {
49+
type: "object",
50+
label: "Payment Method Details",
51+
description: "The payment method details object required for submitting additional payment details. Should contain relevant payment details fields. For more information refer the the [documentation](https://docs.adyen.com/api-explorer/Checkout/71/post/payments#request-paymentMethod).",
52+
optional: true,
53+
},
54+
},
55+
methods: {
56+
createPayment({ data } = {}) {
57+
return this.app.getCheckoutAPI()
58+
.PaymentsApi
59+
.payments(data);
60+
},
61+
},
62+
async run({ $ }) {
63+
const {
64+
createPayment,
65+
amountCurrency,
66+
amountValue,
67+
merchantAccount,
68+
reference,
69+
returnUrl,
70+
paymentMethodType,
71+
paymentMethodDetails,
72+
} = this;
73+
74+
const response = await createPayment({
75+
data: {
76+
amount: {
77+
currency: amountCurrency,
78+
value: amountValue,
79+
},
80+
merchantAccount,
81+
reference,
82+
returnUrl,
83+
paymentMethod: {
84+
...paymentMethodDetails,
85+
type: paymentMethodType,
86+
},
87+
},
88+
});
89+
$.export("$summary", "Successfully created payment.");
90+
return response;
91+
},
92+
};
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import app from "../../adyen.app.mjs";
2+
3+
export default {
4+
key: "adyen-refund-payment",
5+
name: "Refund Payment",
6+
description: "Refunds a captured payment. [See the documentation](https://docs.adyen.com/api-explorer/checkout/71/post/payments/(paymentpspreference)/refunds)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
paymentPspReference: {
12+
propDefinition: [
13+
app,
14+
"paymentPspReference",
15+
],
16+
},
17+
merchantAccount: {
18+
propDefinition: [
19+
app,
20+
"merchantAccount",
21+
],
22+
},
23+
amountCurrency: {
24+
propDefinition: [
25+
app,
26+
"amountCurrency",
27+
],
28+
},
29+
amountValue: {
30+
propDefinition: [
31+
app,
32+
"amountValue",
33+
],
34+
},
35+
},
36+
methods: {
37+
refundPayment({
38+
paymentPspReference, data,
39+
} = {}) {
40+
return this.app.getCheckoutAPI()
41+
.ModificationsApi
42+
.refundCapturedPayment(paymentPspReference, data);
43+
},
44+
},
45+
async run({ $ }) {
46+
const {
47+
refundPayment,
48+
paymentPspReference,
49+
merchantAccount,
50+
amountCurrency,
51+
amountValue,
52+
} = this;
53+
54+
const response = await refundPayment({
55+
paymentPspReference,
56+
data: {
57+
merchantAccount,
58+
amount: {
59+
currency: amountCurrency,
60+
value: amountValue,
61+
},
62+
},
63+
});
64+
$.export("$summary", `Successfully refunded payment with PSP Reference \`${response.paymentPspReference}\`.`);
65+
return response;
66+
},
67+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import app from "../../adyen.app.mjs";
2+
3+
export default {
4+
key: "adyen-submit-details",
5+
name: "Submit Additional Payment Details",
6+
description: "Submits additional details for a payment. [See the documentation](https://docs.adyen.com/api-explorer/checkout/71/post/payments/details)",
7+
version: "0.0.2",
8+
type: "action",
9+
props: {
10+
app,
11+
details: {
12+
type: "object",
13+
label: "Details",
14+
description: "Use this collection to submit the details that were returned as a result of the **Create Payment** action call.",
15+
},
16+
},
17+
methods: {
18+
submitAdditionalDetails({ data } = {}) {
19+
return this.app.getCheckoutAPI()
20+
.PaymentsApi
21+
.paymentsDetails(data);
22+
},
23+
},
24+
async run({ $ }) {
25+
const {
26+
submitAdditionalDetails,
27+
details,
28+
} = this;
29+
30+
const response = await submitAdditionalDetails({
31+
data: {
32+
details,
33+
},
34+
});
35+
$.export("$summary", "Successfully submitted additional payment details.");
36+
return response;
37+
},
38+
};

components/adyen/adyen.app.mjs

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
1+
import adyen from "@adyen/api-library";
2+
13
export default {
24
type: "app",
35
app: "adyen",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
merchantAccount: {
8+
type: "string",
9+
label: "Merchant Account",
10+
description: "The merchant account identifier, with which you want to process the transaction.",
11+
},
12+
amountCurrency: {
13+
type: "string",
14+
label: "Currency",
15+
description: "The currency of the payment amount. The three-character [ISO currency code](https://docs.adyen.com/development-resources/currency-codes).",
16+
},
17+
amountValue: {
18+
type: "integer",
19+
label: "Value",
20+
description: "The amount of the transaction, in [minor units](https://docs.adyen.com/development-resources/currency-codes).",
21+
},
22+
paymentMethodType: {
23+
type: "string",
24+
label: "Payment Method Type",
25+
description: "The payment method used for the payment. For example `scheme` or `paypal`. For the full list of payment methods, refer to the [documentation](https://docs.adyen.com/api-explorer/Checkout/71/post/payments#request-paymentMethod).",
26+
async options({ merchantAccount }) {
27+
if (!merchantAccount) {
28+
return [];
29+
}
30+
const { paymentMethods } = await this.listPaymentMethods({
31+
data: {
32+
merchantAccount,
33+
},
34+
});
35+
return paymentMethods.map(({
36+
name: label, type: value,
37+
}) => ({
38+
label,
39+
value,
40+
}));
41+
},
42+
},
43+
paymentPspReference: {
44+
type: "string",
45+
label: "Payment PSP Reference",
46+
description: "The PSP reference of the payment for which you want to perform the action.",
47+
},
48+
},
549
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
50+
getClient() {
51+
const {
52+
api_key: apiKey,
53+
live_endpoint_url_prefix: liveEndpointUrlPrefix,
54+
environment,
55+
} = this.$auth;
56+
const isLiveEnv = environment === "LIVE";
57+
return new adyen.Client({
58+
apiKey,
59+
environment,
60+
...(isLiveEnv && {
61+
liveEndpointUrlPrefix,
62+
}),
63+
});
64+
},
65+
getCheckoutAPI() {
66+
return new adyen.CheckoutAPI(this.getClient());
67+
},
68+
listPaymentMethods({
69+
data, options,
70+
} = {}) {
71+
return this.getCheckoutAPI().PaymentsApi.paymentMethods(data, options);
972
},
1073
},
1174
};

0 commit comments

Comments
 (0)