Giter Site home page Giter Site logo

swanandmaratheblisstering / ti.androidpay Goto Github PK

View Code? Open in Web Editor NEW

This project forked from appwerft/ti.androidpay

0.0 2.0 0.0 4.88 MB

Axway Titanium module for Android payment

License: Other

C++ 1.61% Makefile 12.10% Java 86.13% JavaScript 0.07% Shell 0.09%

ti.androidpay's Introduction

Ti.AndroidPay

This a Axway Titanium module for Android payment Documentation.

Installation

First on CLI

gittio install ti.android

Then you have to add the module to your project inside tiapp.xml.

Constants

  • WALLET_ENVIRONMENT_TEST
  • WALLET_ENVIRONMENT_PRODUCTION
  • RESULT_OK
  • RESULT_ERROR
  • ROLE_REGULAR
  • ROLE_SHIPPING
  • ROLE_TAX

Usage

Is the user ready to pay with Android Pay?

Before starting the Android Pay flow, use the isReadyToPay() method to check whether the user has the Android Pay app installed and is ready to pay. If this method returns true, show the Android Pay button. If it returns false, display other checkout options along with text notifying the user to set up the Android Pay app.

const AndroidPay = require('ti.androidpay');

AndroidPay.addEventListener('load', function(e) {
  console.log(e);
  handlePayment();
});

AndroidPay.isReadyToPay({
  onload: function(e) {
    console.log(e);
    handlePayment();
  }
});

You can use either the callbackj or the listener.

Request a Payment Token

Before you can request any wallet information, you must build parameters to inform the Android Pay API what type of payment token you wish to receive in the response. The PaymentMethodTokenizationParameters builder lets you establish the parameters of the token. The inputs you provide to this call depend on how you plan to process payments, and may also vary depending on your payment processor provider. You will initialize either a network token or a payment gateway token.

Request a payment gateway token

If you use Braintree, Stripe, or Vantiv to process payments, you can set provider-specific parameters (a publishable key) to receive a gateway token that you can charge with your provider. Please refer to the Braintree, Stripe or Vantiv developer documentation for more information.

The following example shows how to request a token from Stripe:

let paymentMethodTokenizationParameters = AndroidPay.createPaymentMethodTokenizationParameters({
  gateway: 'stripe',  
  'stripe:publishableKey': publishableKey,  
  'stripe:version': version
});  

Request a network token

Set the tokenization type and add a publicKey parameter as shown:

let paymentMethodTokenizationParameters = AndroidPay.createPaymentMethodTokenizationParameters({  
  type: AndroidPay.NETWORK_TOKEN,
  publicKey: publicKey
}); 

Create a Masked Wallet request

You must create an instance of MaskedWalletRequest to retrieve the Masked Wallet information (such as billing address, shipping address, masked backing payment instrument number, and cart items) from the Android Pay API. The MaskedWalletRequest object must be passed in when you initialize the purchase button in the next section.

At this point, you won't have the user's chosen shipping address from Android Pay, so you must create an estimate of the shipping costs and tax. If you set the shopping cart as shown below, make sure the cart total matches the sum of the line items added to the cart.

Create LineItem

let product = AndroidPay.createLineItem({
  CurrencyCode: 'EUR',
  Description: 'My awesome bicycle',
  Quantity: 2,
  Role: AndroidPay.ROLE_REGULAR,
  TotalPrice: 94.22,	
  UnitPrice: 47.11
});

let shipping = AndroidPay.createLineItem({
  CurrencyCode: 'EUR',
  Description: 'Shipping by DHL',
  Quantity: 1,
  Role: AndroidPay.ROLE_SHIPPING,
  TotalPrice: 5.00,	
  UnitPrice: 5.00
});

let tax = AndroidPay.createLineItem({
  CurrencyCode: 'EUR',
  Description: 'Tax',
  Quantity: 1,
  Role: AndroidPay.ROLE_TAX,
  TotalPrice: 1.00,	
  UnitPrice: 1.00
});

Create Cart

let cart = AndroidPay.createCart({
  CurrencyCode: 'EUR',
  TotalPrice: 104.22
});
cart.addLineItem(product);
cart.addLineItem(tax);
cart.addLineItem(shipping);

Create Wallet

The following example creates the Masked Wallet request using the builder pattern:

let request = AndroidPay.createwWallet({  
  MerchantName: 'Acme Inc',  
  PhoneNumberRequired: true,  
  ShippingAddressRequired: true, 
  CurrencyCode: 'EUR',  
  EstimatedTotalPrice: cartTotal,  
  // Create a Cart with the current line items. Provide all the information  
  // available up to this point with estimates for shipping and tax included.  
  cart: cart,
  PaymentMethodTokenizationParameters: paymentMethodTokenizationParameters
});

ti.androidpay's People

Contributors

appwerft avatar hansemannn avatar

Watchers

James Cloos avatar Swanand 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.