3.0.0 • Published 4 years ago

seamlesspay-web v3.0.0

Weekly downloads
12
License
ISC
Repository
github
Last release
4 years ago

seamlesspay-web

A suite of tools for integrating Seamlesspay in the browser.

Install

npm install seamlesspay-web

Usage

Hosted Fields integration

<form action="/" id="my-sample-form">
  <input type="hidden" name="payment_method_id">
  <label for="card-number">Card Number</label>
  <div id="card-number"></div>

  <label for="expiration-date">Expiration Date</label>
  <div id="expiration-date"></div>

  <input id="my-submit" type="submit" value="Pay" disabled/>
</form>
var submitBtn = document.getElementById('my-submit');
var form = document.getElementById('my-sample-form');

seamlesspay.client.create({
  authorization: CLIENT_PUBLISHABLE_KEY
}, clientDidCreate);

function clientDidCreate(error, client) {
  seamlesspay.hostedFields.create({
    type: 'CREDIT',
    client: client,
    styles: {
      'input': {
        'font-size': '16pt',
        'color': '#3A3A3A'
      },
      '.valid': {
        'color': 'green'
      }
    },
    fields: {
      accountNumber: {
        selector: '#card-number'
      },
      expirationDate: {
        selector: '#expiration-date'
      }
    }
  }, hostedFieldsDidCreate);
}

function hostedFieldsDidCreate(error, hostedFields) {
  submitBtn.addEventListener('click', submitHandler.bind(null, hostedFields));
  submitBtn.removeAttribute('disabled');
}

function submitHandler(hostedFields, event) {
  event.preventDefault();
  submitBtn.setAttribute('disabled', 'disabled');

  hostedFields.tokenize(function (error, payload) {
    if (error) {
      submitBtn.removeAttribute('disabled');
      console.error(error);
    } else {
      form['payment_method_id'].value = payload.token;
      form.submit();
    }
  });
}

Advanced integration

<form action="/" id="my-sample-form">

  <label for="method">Transaction Type</label>
  <div id="method"></div>

  <label for="account-number">Card Number</label>
  <div id="account-number"></div>

  <label for="expiration-date">Expiration Date</label>
  <div id="expiration-date"></div>

  <label for="amount">Amount</label>
  <div id="amount"></div>

  <label for="description">Description</label>
  <input id="description" type="text"/>

  <input id="my-submit" type="submit" value="Pay" disabled/>
</form>
var submitBtn = document.getElementById('my-submit');
var form = document.getElementById('my-sample-form');

seamlesspay.client.create({
  authorization: CLIENT_PUBLISHABLE_KEY,
  transactionApi: {
    url: 'https://your.transaction.processing.server.com'
  }
}, clientDidCreate);

function clientDidCreate(error, client) {
  seamlesspay.hostedFields.create({
    type: 'CREDIT',
    client: client,
    styles: {
      'input': {
        'font-size': '16pt',
        'color': '#3A3A3A'
      },
      '.valid': {
        'color': 'green'
      }
    },
    fields: {
      method: {
        selector: '#method',
        defaultValue: 'sale'
      },
      accountNumber: {
        selector: '#account-number'
      },
      expirationDate: {
        selector: '#expiration-date'
      },
      amount: {
        selector: '#amount'
      }
    }
  }, hostedFieldsDidCreate);
}

function hostedFieldsDidCreate(error, hostedFields) {
  submitBtn.addEventListener('click', submitHandler.bind(null, hostedFields));
  submitBtn.removeAttribute('disabled');
}

function submitHandler(hostedFields, event) {
  event.preventDefault();
  submitBtn.setAttribute('disabled', 'disabled');

  hostedFields.createTransaction({
    description: document.getElementById('description').value
  }, function (error, payload) {
    if (error) {
      submitBtn.removeAttribute('disabled');
      console.error(error);
    } else {
      form['transaction'].value = JSON.stringify(payload);
      form.submit();
    }
  });
}

Payment Request integration

<button id="payment-request-button">Make Payment Request $ 1.00</button>

Check that window.PaymentRequest exists to ensure that Payment Request is supported and available in the browser.

if (window.PaymentRequest) {
  // This browser supports Payment Request
  // Display your Payment Request button
} else {
  alert('Browser does not support Payment Request');
  // Browser does not support Payment Request
  // Set up Hosted Fields, etc.
}

Set up your Payment Request button

var button = document.querySelector('#payment-request-button');

seamlesspay.client.create(
  {
    authorization: CLIENT_PUBLISHABLE_KEY
  },
  clientDidCreate,
);

function clientDidCreate(error, client) {
  if (error) {
    // handle client error here
    return;
  }

  seamlesspay.paymentRequest.create({
    client: client
  }, paymentRequestDidCreate);
}

function paymentRequestDidCreate(error, paymentRequest) {
  if (error) {
    // Handle Payment Request errors here
    return;
  }

  button.addEventListener('click', submitHandler.bind(null, paymentRequest));
}

function submitHandler(paymentRequest, event) {
  event.preventDefault();

  paymentRequest.tokenize({
    details: {
      total: {
        label: 'Total Amount',
        amount: {
          currency: 'USD',
          value: '1.00'
        }
      }
    },
    options: {
      requestPayerName: true,
      requestPayerPhone: true,
      requestPayerEmail: true
    }
  }, function(error, payload) {
    if (error) {
      // Handle errors from processing payment request
      return;
    }

    // Send payload.token to your server here
    alert(payload.token)
  });
}

For more examples, see the reference.

3.0.0

4 years ago

2.4.0

4 years ago

2.2.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.10.2

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.1

4 years ago

1.9.0

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.1

6 years ago

1.0.0-rc

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago