Payment Method

A comprehensive set of methods to create, update, and manage user payment instruments, with support for multiple payment gateways.

create

Creates a new user payment method using a stripe token. Emits the PelcroPaymentMethodCreated DOM events when the response is returned successfully.

Example

window.Pelcro.paymentMethods.create(
  {
    auth_token: window.Pelcro.user.read().auth_token, 
  	token: "stripe_token",
  },
  (error, response) => {
    if (error) {
    	return console.log("error", error.message);
    }
    
    const createdSource = response.data.sources[response.data.sources.length - 1];
    console.log(createdSource);
  }
)

Parameters

ParameterType
auth_token string
token string
gateway (Required for gateways other than Stripe)string

update

Updates a payment method's details using payment method id and other parameters that differs based on the gateway. Emits the PelcroPaymentMethodUpdated DOM events when the response is returned successfully.

Example for Stripe gateway

window.Pelcro.paymentMethods.update(
  {
    auth_token: window.Pelcro.user.read().auth_token,
    payment_method_id: 1234,
    gateway: "stripe",
    exp_month: 08,
    exp_year: 2029,
    is_default: true,
  },
  (error, response) => {
    if (error) {
      return console.log("error", error.message);
    }

    const updatedPaymentMethod = response.data;
    console.log(updatedPaymentMethod);
  }
);

Parameters reference for Stripe

ParameterType
auth_token string
payment_method_id number
gateway string
exp_month number
exp_year number
is_defaultboolean

Example for Vantiv gateway

window.Pelcro.paymentMethods.update(
  {
    auth_token: window.Pelcro.user.read().auth_token,
    payment_method_id: 1234,
    gateway: "vantiv",
    paypageRegistrationId: paypageRegistrationId,
    bin: bin,
    type: "MC",
    firstSix: 526489,
    lastFour: 4444,
    exp_month: 08,
    exp_year: 2029,
    is_default: true,
  },
  (error, response) => {
    if (error) {
      return console.log("error", error.message);
    }

    const updatedPaymentMethod = response.data;
    console.log(updatedPaymentMethod);
  }
);

Parameters reference for Vantiv

ParameterType
auth_token string
payment_method_id number
gateway string
exp_month number
exp_year number
is_defaultboolean
paypageRegistrationId string
bin string
type string
firstSix number
lastFour number

list

Lists the payment methods existing for the user.

Example

window.Pelcro.paymentMethods.list(
  {
    auth_token: window.Pelcro.user.read().auth_token
  },
  (error, response) => {
    if (error) {
      return console.log("error", error.message);
    }

    const paymentMethodList = response.data;
    console.log(paymentMethodList);
  }
);

Parameters

ParameterType
auth_token string

getPaymentMethod

Retrieve information about a specific payment method using the payment method id.

Example

window.Pelcro.paymentMethods.getPaymentMethod(
  {
    auth_token: window.Pelcro.user.read().auth_token,
    payment_method_id: 1234
  },
  (error, response) => {
    if (error) {
      return console.log("error", error.message);
    }

    const paymentMethod = response.data;
    console.log(paymentMethod);
  }
);

Parameters

ParameterType
auth_token string
payment_method_id number

deletePaymentMethod

Deletes a stored payment method using the payment method id. Emits the PelcroPaymentMethodDeleted DOM events when the response is returned successfully.

Example

window.Pelcro.paymentMethods.deletePaymentMethod(
  {
    auth_token: window.Pelcro.user.read().auth_token,
    payment_method_id: 1234
  },
  (error, response) => {
    if (error) {
      return console.log("error", error.message);
    }

    // No response if success
  }
);

Parameters

ParameterType
auth_token string
payment_method_id number