1.0.5 • Published 2 years ago

tilled-payment v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Tilled Payment

It is a Payment Methods for use in backend or frontend

Install

#npm
npm i tilled-payment fenextjs-error
#yarn
yarn add tilled-payment fenextjs-error
#bun
bun i tilled-payment fenextjs-error

Instance

import { __Tilled } from "tilled-payment";

const tilled = __Tilled({
    mode: "sandbox",
    merchant_account_id: "",
    email: "",
    password: "",
});

Use

Create Customer

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";
const resultCustomer = await tilled.customer.onCreateCustomer({
    email,
    first_name,
    last_name,
    middle_name,
    phone,
});
if (resultCustomer instanceof ErrorFenextjs) {
    console.log("resultCustomer", resultCustomer);
    return;
}
console.log("resultCustomer", resultCustomer?.data);

Create Payment Method

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";

const resultPaymentMethod = await tilled.payment.onCreatePaymentMethod({
    billing_details: {
        address: {
            city,
            country,
            state,
            street,
            street2,
            zip,
        },
        email,
        name,
        phone,
    },
    card: {
        cvc,
        exp_month,
        exp_year,
        number,
    },
    type: "card",
});
if (resultPaymentMethod instanceof ErrorFenextjs) {
    console.log("resultPaymentMethod", resultPaymentMethod);
    return;
}

Attach a Customer to Payment Method

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";

const resultAttachCustomerPaymentMethod =
    await tilled.payment.onAttachCustomerPaymentMethod({
        id,
        customer_id,
    });
if (resultAttachCustomerPaymentMethod instanceof ErrorFenextjs) {
    console.log(
        "resultAttachCustomerPaymentMethod",
        resultAttachCustomerPaymentMethod,
    );
    return;
}
console.log(
    "resultAttachCustomerPaymentMethod",
    resultAttachCustomerPaymentMethod?.data,
);

Create Payment Intent

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";

const resultCreatePaymentIntent = await tilled.payment.onCreatePaymentIntent({
    amount: 1000,
    currency: "usd",
    payment_method_types: ["card"],
    payment_method_id,
});
if (resultCreatePaymentIntent instanceof ErrorFenextjs) {
    console.log("resultCreatePaymentIntent", resultCreatePaymentIntent);
    return;
}
console.log("resultCreatePaymentIntent", resultCreatePaymentIntent?.data);

Create Subscription

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";
const resultCreateSubscription = await tilled.subscription.onCreateSubscription(
    {
        billing_cycle_anchor: new Date().toISOString(),
        currency: "usd",
        customer_id,
        payment_method_id,
        interval_unit: "month",
        price: 10000,
    },
);
if (resultCreateSubscription instanceof ErrorFenextjs) {
    console.log("resultCreateSubscription", resultCreateSubscription);
    return;
}
console.log("resultCreateSubscription", resultCreateSubscription?.data);

Cancel Subscription

import { ErrorFenextjs } from "fenextjs-error/cjs/Fenextjs";

const resultCancelSubscription = await tilled.subscription.onCancelSubscription(
    {
        id,
    },
);
if (resultCancelSubscription instanceof ErrorFenextjs) {
    console.log("resultCancelSubscription", resultCancelSubscription);
    return;
}
console.log("resultCancelSubscription", resultCancelSubscription?.data);
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago