Git Product home page Git Product logo

openpay-masterpass's Introduction

openpay-masterpass

JavaScript plugin which help integrate Masterpass in your web app.

Add js dependence

Use this Masterpass js for TEST in SANDBOX environment

<script type="text/javascript" src="https://sandbox.static.masterpass.com/dyn/js/switch/integration/MasterPass.client.js"></script>

Use this Masterpass js for PRODUTION environment

<script type="text/javascript" src="https://static.masterpass.com/dyn/js/switch/integration/MasterPass.client.js"></script>

Add Openpay js

<script type='text/javascript' src="https://openpay.s3.amazonaws.com/openpay.v1.min.js"></script>

Add openpay-masterpass.js

<script type="text/javascript" src="${contextPath}/js/openpay/masterpass/openpay-masterpass.js"></script>

Set Openpay api keys

  OpenPay.setId('mYourMerchantId');
  OpenPay.setApiKey('pk_yourPublicKey');
  OpenPay.setSandboxMode(true);// set false to go production

Configure event for Masterpass button

<div class="MasterPassBtnExample">
	<a href="#"> <img src="https://www.mastercard.com/mc_us/wallet/img/en/US/mcpp_wllt_btn_chk_180x042px.png"></a>
</div>
OpenpayMasterpass.configureButton(".MasterPassBtnExample a", {
      originUrl : 'https://myWebApp/demo/masterpass/main',
      callbackUrl : 'https://myWebApp/demo/masterpass/main',
      enableShippingAddress : true,
      successCallback : yourSuccessConfigureButtonCallback, // See an example below...
      failureCallback : yourFailureCallback,
      cancelCallback : yourCancelCallback,
      shoppingCart : {//Shoping cart
        currency: "MXN",  //Currency
        subtotal: "123.00",  //Total Amount
        items: [ //Optionally an arry of items
          {
            description : "Pen 3d", //Some description
            quantity : 2,
            value : "100.00", //Amount
            imageUrl : "https://cdn.pixabay.com/photo/2012/04/13/17/57/pen-33077_960_720.png" //Some image url
          },
          {
            description : "Pencil del futuro",
            quantity : 1,
            value : "23.00",
            imageUrl : "http://i50.twenga.com/suministros/lapiz/lapices-staedtler-noris-hb-tp_3981652568322654320f.jpg"
          }
        ]
      }
});

Your SuccessConfigurationButtonCallback

var successConfigureButtonCallback = function(response) {
  OpenpayMasterpass.getCheckoutData(
    response, //this is required
    yourSuccessCheckoutCallback, //You must implement this. See an example below...
    yourFailureCheckoutCallback  //And this too!
  );
};

Your SuccessCheckoutCallback

  var successCheckoutCallback = function(response) {
  var data = response.data;
  console.log('DATA:');
  console.log(data);
  $("#tokenCard").val(data.id);//this is your openpay Token card to use in the charge request for Openpay

  var card = data.card;
  console.log(data.card);
  $("#holderName").text(card.holder_name);
  $("#cardNumber").text(card.card_number);
  $("#expirationDate").text(card.expiration_month + '/' +card.expiration_year);

  var customer = data.customer;
  $("#customerName").text(customer.name);
  $("#customerEmail").text(customer.email);
  $("#customerLastName").text(customer.last_name);
  $("#customerPhone").text(customer.phone_number);

  var sa = data.shipping_address; 
  if (sa) {
    $("#postalCode").text(sa.postal_code);
    $("#country").text(sa.country_code);
    $("#saPhone").text(sa.phone_number);
    $("#recipient").text(sa.recipient);
    $("#line1").text(sa.line1);
    $("#line2").text(sa.line2);
    $("#line3").text(sa.line3);
    $("#state").text(sa.state);
    $("#city").text(sa.city);
  }
};

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.