Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { parseObject } from "../../common/utils.mjs";
import app from "../../mamo_business.app.mjs";

export default {
key: "mamo_business-create-payment-link",
name: "Create Payment Link",
version: "0.0.1",
description: "Generate a vanilla or subscription payment link. [See the documentation](https://mamopay.readme.io/reference/post_links)",
type: "action",
props: {
app,
title: {
type: "string",
label: "Title",
description: "The title of the payment link.",
},
description: {
type: "string",
label: "Description",
description: "Payment description. This will appear on the payment checkout page.",
optional: true,
},
capacity: {
type: "integer",
label: "Capacity",
description: "The capacity will be ignored when the subscription params exist and value will be null.",
optional: true,
},
active: {
type: "boolean",
label: "Active",
description: "Whether the payment is active or not.",
optional: true,
},
returnUrl: {
type: "string",
label: "Return URL",
description: "The URL which the customer will be redirected to after a successful payment.",
optional: true,
},
failureReturnUrl: {
type: "string",
label: "Failure Return URL",
description: "The URL which the customer will be redirected to after a failure payment.",
optional: true,
},
processingFeePercentage: {
type: "integer",
label: "Processing Fee Percentage",
description: "The percentage of the transaction that is the fee.",
optional: true,
},
amount: {
type: "string",
label: "Amount",
description: "The value number of the payment.",
optional: true,
},
amountCurrency: {
type: "string",
label: "Amount Currency",
description: "The currency that the transaction will be charged.",
default: "AED",
options: [
"AED",
"USD",
"EUR",
"GBP",
"SAR",
],
},
isWidget: {
type: "boolean",
label: "Is Widget",
description: "Generate widget payment link.",
optional: true,
},
enableTabby: {
type: "boolean",
label: "Enable Tabby",
description: "Enables the ability for customers to buy now and pay later.",
optional: true,
},
enableMessage: {
type: "boolean",
label: "Enable Message",
description: "Enables the ability for customers to add a message during the checkout process.",
optional: true,
},
enableTips: {
type: "boolean",
label: "Enable Tips",
description: "Enables the tips option. This will be displayed on the first screen.",
optional: true,
},
enableCustomerDetails: {
type: "boolean",
label: "Enable Customer Details",
description: "Enables adding customer details such as the name, email, and phone number. This screen will be displayed before the payment details screen.",
optional: true,
},
enableQuantity: {
type: "boolean",
label: "Enable Quantity",
description: "Enable the payment link to be used multiple times.",
optional: true,
},
enableQrCode: {
type: "boolean",
label: "Enable QR Code",
description: "Adds the ability to verify a payment through a QR code.",
optional: true,
},
sendCustomerReceipt: {
type: "boolean",
label: "Send Customer Receipt",
description: "Enables the sending of customer receipts.",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "The first name of customer which will pre-populate in card info step.",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of customer which will pre-populate in card info step.",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The email of customer which will pre-populate in card info step.",
optional: true,
},
externalId: {
type: "string",
label: "External Id",
description: "The external ID of your choice to associate with payments captured by this payment link.",
optional: true,
},
customData: {
type: "object",
label: "Custom Data",
description: "An object with custom data of the payment link.",
optional: true,
},
isRecurring: {
type: "boolean",
label: "Is Recurring",
description: "Whether this payment link is for a recurring payment.",
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (this.isRecurring) {
props.frequency = {
type: "string",
label: "Frequency",
description: "Defines the interval that this subscription will be run on.",
options: [
"weekly",
"monthly",
"annually",
],
};
props.frequencyInterval = {
type: "integer",
label: "Frequency Interval",
description: "Defines how often this subscription will run. This will be based on the frequency property defined above.",
};
props.endDate = {
type: "string",
label: "End Date",
description: "The last date this subscription could run on. Format: YYYY/MM/DD",
};
props.paymentQuantity = {
type: "string",
label: "Payment Quantity",
description: "Number of times this subscription will occur. If end_date defined, end_date takes precedence.",
};
}
return props;
},
async run({ $ }) {
const {
app,
returnUrl,
failureReturnUrl,
processingFeePercentage,
amountCurrency,
isWidget,
enableTabby,
enableMessage,
enableTips,
enableCustomerDetails,
enableQuantity,
enableQrCode,
sendCustomerReceipt,
firstName,
lastName,
externalId,
customData,
isRecurring,
frequency,
frequencyInterval,
endDate,
paymentQuantity,
...data
} = this;

const obj = {
return_url: returnUrl,
failure_return_url: failureReturnUrl,
processing_fee_percentage: processingFeePercentage,
amount_currency: amountCurrency,
is_widget: isWidget,
enable_tabby: enableTabby,
enable_message: enableMessage,
enable_tips: enableTips,
enable_customer_details: enableCustomerDetails,
enable_quantity: enableQuantity,
enable_qr_code: enableQrCode,
send_customer_receipt: sendCustomerReceipt,
first_name: firstName,
last_name: lastName,
external_id: externalId,
custom_data: customData && parseObject(customData),
...data,
};
if (isRecurring) {
obj.subscription = {
frequency,
frequency_interval: frequencyInterval,
end_ate: endDate,
payment_quantity: paymentQuantity,
};
}

const response = await app.createPaymentLink({
$,
data: obj,
});

$.export("$summary", `A new payment link with Id: ${response.id} was successfully created!`);
return response;
},
};
6 changes: 6 additions & 0 deletions components/mamo_business/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const parseObject = (obj) => {
if (typeof obj != "object") {
return JSON.parse(obj);
}
return obj;
};
46 changes: 41 additions & 5 deletions components/mamo_business/mamo_business.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "mamo_business",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_apiUrl() {
return `https://${this.$auth.environment}.mamopay.com/manage_api/v1`;
},
_getHeaders() {
return {
"Authorization": `Bearer ${this.$auth.api_key}`,
};
},
_makeRequest({
$ = this, path, ...opts
}) {
const config = {
url: `${this._apiUrl()}/${path}`,
headers: this._getHeaders(),
...opts,
};

return axios($, config);
},
createHook(args = {}) {
return this._makeRequest({
method: "POST",
path: "webhooks",
...args,
});
},
createPaymentLink(args = {}) {
return this._makeRequest({
method: "POST",
path: "links",
...args,
});
},
deleteHook(hookId) {
return this._makeRequest({
method: "DELETE",
path: `webhooks/${hookId}`,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/mamo_business/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/mamo_business",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Mamo Business Components",
"main": "mamo_business.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.5.1"
}
}
}
56 changes: 56 additions & 0 deletions components/mamo_business/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import app from "../../mamo_business.app.mjs";

export default {
dedupe: "unique",
props: {
app,
http: {
type: "$.interface.http",
customResponse: true,
},
db: "$.service.db",
},
hooks: {
async activate() {
const data = await this.app.createHook({
data: {
url: this.http.endpoint,
enabled_events: this.getEvent(),
},
});

this._setHookId(data.id);
},
async deactivate() {
const id = this._getHookId("hookId");
await this.app.deleteHook(id);
},
},
methods: {
emitEvent(body) {
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
_getHookId() {
return this.db.get("hookId");
},
_setHookId(hookId) {
this.db.set("hookId", hookId);
},
generateMeta(body) {
return {
id: `${body.id}${body.created_date}`,
summary: this.getSummary(body),
ts: new Date(),
};
},
},
async run({ body }) {
if (body.ping) {
return this.http.respond({
status: 200,
});
}
this.emitEvent(body);
},
};
Loading