Skip to content

wallet module for Apple Pay & Google Pay integrations

License

Notifications You must be signed in to change notification settings

fluidpay/walletjs

Repository files navigation

@fluidpay/walletjs

Installation

$ npm install @fluidpay/walletjs

Basic Usage

Apple Pay

html
<button type="button" onclick="submitApplePay()">Apple Pay Button</button>
js
import walletjs from "@fluidpay/walletjs";

const ap = new walletjs.ApplePay({
  key: "myKey0123456789",
  domain: "sandbox.fluidpay.com",
  domainName: "", // optionally override the Merchant Domain referenced in their certificate.
  payment: {
    merchantCapabilities: ["supports3DS", "supportsCredit", "supportsDebit"],
    supportedNetworks: ["visa", "masterCard", "discover"],
    countryCode: "US",
    version: 3,
    merchantIdentifier: "my.merchant.id.app",
    // Use requiredBillingContactFields to request the user's
    // billing address that is associated with their payment method.
    requiredBillingContactFields: ["email", "name", "phone", "postalAddress"], // Default undefinied
  },

  details: {
    total: {
      label: "Total Amount",
      amount: { currency: "USD", value: "10.61" },
    },
  },

  options: {
    requestShipping: false,
  },
});

function submitApplePay() {
  var resp = ap.submit();
  console.log(resp);
}

Response

success
{ "status": "success", "token": "aBCd1234" };
fail
{ "status": "fail", "error": "missing required parameter - key" };

Google Pay™

js
import walletjs from "@fluidpay/walletjs";

// Create a new Google Pay instance with your
// given settings.
let gp = new walletjs.GooglePay({
  container: "#container",
  merchantName: "Example Merchant",
  gatewayMerchantId: "<PUBLIC_API_KEY>",
  allowedCardNetworks: ["VISA"],
  allowedCardAuthMethods: ["PAN_ONLY"],
  transactionInfo: {
    countryCode: "US",
    currencyCode: "USD",
    totalPrice: "1.23",
  },
  // Deal with response from payment clicked
  onGooglePaymentButtonClicked: (paymentDataRequest) => {
    paymentDataRequest
      .then((paymentData) => {
        // Get the token.
        const token = paymentData.paymentMethodData.tokenizationData.token;

        // Send the token to your backend server, which will
        // then call our API to create a new transaction with
        // the token set as the payment method.
      })
      .catch((err) => {
        console.log(err);
      });
  },
});
HTML (Template)
<!-- The div where the button will go -->
<div id="container"></div>

Additional Resources

About

wallet module for Apple Pay & Google Pay integrations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published