GithubHelp home page GithubHelp logo

frames-vue's Introduction

❗️BETA

This project is a minimal Vue wrapper of Checkout.com Frames. This version only supports the multiple iframes configuration.

πŸš€ Install

npm install frames-vue

🌐 Load the CDN script

Make sure that you load the Checkout.com CDN script before you mount any Frames components. You can add this, for example, in your index.html file.

<script src="https://cdn.checkout.com/js/framesv2.min.js"></script>

If you use server-side rendering, such as with Nuxt.js, you can add this inside your head object script array:

head: {
    script: [
      {
        src: "https://cdn.checkout.com/js/framesv2.min.js",
      },
    ],
  }

✨ Import the components

import { Frames, CardNumber, ExpiryDate, Cvv } from "frames-vue";

πŸ“– Example Usage

To tokenize the payment card, this wrapper includes method submitCard(). In the below example, we call this when the "Pay Now" button is clicked.

<template>
  <div id="payment-form">
    <Frames
      :config="config"
      @ready="ready"
      @frameFocus="frameFocus"
      @cardTokenized="cardTokenized"
    />
    <CardNumber />
    <ExpiryDate />
    <Cvv />
    <button id="pay-button" @click="submitCard">Pay Now</button>
  </div>
</template>

<script>
import { Frames, CardNumber, ExpiryDate, Cvv } from "frames-vue";

export default {
  name: "App",
  components: {
    Frames,
    CardNumber,
    ExpiryDate,
    Cvv,
  },
  data() {
    return {
      config: {
        debug: true,
        publicKey: "pk_test_42e79f8e-28ad-4eed-8586-2764b1cc78e2",
        localization: {
          cardNumberPlaceholder: "Card number",
          expiryMonthPlaceholder: "MM",
          expiryYearPlaceholder: "YY",
          cvvPlaceholder: "CVV",
        },
        style: {
          base: {
            fontSize: "17px",
          },
        },
      },
    };
  },
  methods: {
    cardTokenized(e) { console.log(`Card token: ${e.token}`) },
    ready(e) { console.log("ready", e) },
    frameFocus(e) { console.log("frameFocus", e) },
    submitCard() { Frames.submitCard() },
  },
};
</script>

πŸ’³ Cardholder

For cases where you render the payment form at the same time as the billing and cardholder name input, you can use method setCardholder() to update Frames with this data before submitting.

<template>
...
<input
  id="cardholder-name"
  placeholder="Cardholder Name"
  v-model="config.cardholder.name"
/>
<input
  id="cardholder-phone"
  placeholder="Phone Number"
  v-model="config.cardholder.phone"
/>
<input
  id="cardholder-address-one"
  placeholder="Address 1"
  v-model="config.cardholder.billingAddress.addressLine1"
/>
...
<Frames :config="config" />
...
</template>

<script>
...
  data() {
    return {
      config: {
        cardholder: {
          name: "",
          billingAddress: {
            addressLine1: "",
            addressLine2: "",
            zip: "",
            city: "",
            state: "",
            country: "GB"
          },
          phone: "",
        },
        ...
      },
    };
  },
  methods: {
    submitCard() {
      Frames.setCardholder(this.config.cardholder);
      Frames.submitCard();
    },
  },
  ...
</script>

Props

prop description
config The config is an object following Checkout.com Frames reference.
ready Triggered when Frames is registered on the global namespace and safe to use.
frameActivated Triggered when the form is rendered.
frameFocus Triggered when an input field receives focus. Use it to check the validation status and apply the wanted UI changes.
frameBlur Triggered after an input field loses focus. Use it to check the validation status and apply the wanted UI changes.
frameValidationChanged Triggered when a field's validation status has changed. Use it to show error messages or update the UI.
paymentMethodChanged Triggered when a valid payment method is detected based on the card number being entered. Use this event to change the card icon.
cardValidationChanged Triggered when the state of the card validation changes.
cardSubmitted Triggered when the card form has been submitted.
cardTokenized Triggered after a card is tokenized.
cardTokenizationFailed Triggered if the card tokenization fails.

Functions

function description
init Initializes (or re-initializes) Frames.
isCardValid Returns the state of the card form validation.
submitCard Submits the card form if all form values are valid.
addEventHandler Adds a handler that is called when the specified event is triggered.
removeEventHandler Removes a previously added handler from an event by providing the event name and handler as arguments in the method.
removeAllEventHandlers Removes all handlers added to the event specified.
enableSubmitForm Retains the entered card details and allows you to resubmit the payment form.

frames-vue's People

Contributors

stephen-gilbert-cko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.