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
104 changes: 104 additions & 0 deletions components/chargify/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import chargify from "../../chargify.app.mjs";

export default {
key: "chargify-create-customer",
name: "Create Customer",
description: "Creates a new customer in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/customers/create-customer)",
version: "0.0.1",
type: "action",
props: {
chargify,
firstName: {
type: "string",
label: "First Name",
description: "The first name of the customer",
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the customer",
},
email: {
type: "string",
label: "Email",
description: "The email of the customer",
},
organization: {
type: "string",
label: "Organization",
description: "The organization of the customer",
optional: true,
},
address: {
type: "string",
label: "Street Address",
description: "Street address of the customer (line 1)",
optional: true,
},
address2: {
type: "string",
label: "Street Address (line 2)",
description: "Street address of the customer (line 2)",
optional: true,
},
city: {
type: "string",
label: "City",
description: "City of the customer",
optional: true,
},
state: {
type: "string",
label: "State",
description: "State/Region of the customer",
optional: true,
},
zip: {
type: "string",
label: "Zip",
description: "Zip code of the customer",
optional: true,
},
country: {
type: "string",
label: "Country",
description: "The country code of the customer. Example: `US`",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "Phone number of the customer",
optional: true,
},
taxExempt: {
type: "boolean",
label: "Tax Exempt",
description: "Set to `true` if the customer is tax exempt.",
optional: true,
},
},
async run({ $ }) {
const { customer } = await this.chargify.createCustomer({
$,
data: {
customer: {
first_name: this.firstName,
last_name: this.lastName,
email: this.email,
organization: this.organization,
address: this.address,
address_2: this.address2,
city: this.city,
state: this.state,
zip: this.zip,
country: this.country,
phone: this.phone,
tax_exempt: this.taxExempt,
},
},
});
$.export("$summary", `Successfully created customer with ID ${customer.id}`);
return customer;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import chargify from "../../chargify.app.mjs";

export default {
key: "chargify-create-subscription",
name: "Create Subscription",
description: "Establishes a new subscription for a given customer in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/subscriptions/create-subscription)",
version: "0.0.1",
type: "action",
props: {
chargify,
customerId: {
propDefinition: [
chargify,
"customerId",
],
},
productId: {
propDefinition: [
chargify,
"productId",
],
},
couponCode: {
propDefinition: [
chargify,
"couponCode",
],
},
nextBillingAt: {
propDefinition: [
chargify,
"nextBillingAt",
],
},
paymentCollectionMethod: {
propDefinition: [
chargify,
"paymentCollectionMethod",
],
},
},
async run({ $ }) {
const response = await this.chargify.createSubscription({
$,
data: {
subscription: {
customer_id: this.customerId,
product_id: this.productId,
coupon_code: this.couponCode,
next_billing_at: this.nextBillingAt,
payment_collection_method: this.paymentCollectionMethod,
},
},
});
$.export("$summary", `Successfully created subscription with ID: ${response.subscription.id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import chargify from "../../chargify.app.mjs";

export default {
key: "chargify-update-subscription",
name: "Update Subscription",
description: "Modifies an existing subscription in Chargify. [See the documentation](https://developers.maxio.com/http/advanced-billing-api/api-endpoints/subscriptions/update-subscription)",
version: "0.0.1",
type: "action",
props: {
chargify,
subscriptionId: {
propDefinition: [
chargify,
"subscriptionId",
],
},
productId: {
propDefinition: [
chargify,
"productId",
],
optional: true,
},
couponCode: {
propDefinition: [
chargify,
"couponCode",
],
},
nextBillingAt: {
propDefinition: [
chargify,
"nextBillingAt",
],
},
paymentCollectionMethod: {
propDefinition: [
chargify,
"paymentCollectionMethod",
],
},
},
async run({ $ }) {
const response = await this.chargify.updateSubscription({
$,
subscriptionId: this.subscriptionId,
data: {
subscription: {
product_id: this.productId,
coupon_code: this.couponCode,
next_billing_at: this.nextBillingAt,
payment_collection_method: this.paymentCollectionMethod,
},
},
});
$.export("$summary", `Successfully updated subscription ${this.subscriptionId}`);
return response;
},
};
Loading
Loading