Giter Site home page Giter Site logo

capacitor-apple-pay-new's Introduction

Capacitor plugin to implement payment function via Apple Pay

Плагин находится на стадии разработки!

The plugin is under development!

demo application: GitHub

Install

npm i capacitor-apple-pay

npx cap sync ios

Import TS definition for VSCode

for some reason type definitions don't work: declare module '@capacito/core' { interface PluginRegistry { ...

import { ApplePayPlugin } from 'capacitor-apple-pay'
import { Plugins } from '@capacitor/core'
const ApplePay = Plugins.ApplePay as ApplePayPlugin;

Can make payments

const { isPayment } = await ApplePay.canMakePayments();

// OR

const { isPayment } = await ApplePay.canMakePayments({
  usingNetworks: [ ... ];
  capabilities: [ ... ];
});

if (isPayment) {
    // ... Request payment
}

Make payment request

See docs: https://developer.apple.com/documentation/passkit/pkpaymentrequest

const paymentRequest = {
    // Requiered
    merchantIdentifier: "com.apple.testing",
    paymentSummaryItems: [
      {
        label: 'order #1001',
        amount: 120.57,
        // type: 'pending' // or default: final
      },
      // ...
    ],

    // Outher
    countryCode: 'US',
    currencyCode: 'USD',

    supportedNetworks: [
      'mastercard', 'visa', 'amex',
      'quicPay', 'chinaUnionPay', 'discover',
      'interac', 'privateLabel'
    ],

    merchantCapabilities: [
      'capability3DS', 'capabilityCredit',
      'capabilityDebit', 'capabilityEMV'
    ],

    requiredShippingContactFields: [
      'emailAddress', 'name', 'phoneNumber',
      'phoneticName', 'postalAddress'
    ],

    requiredBillingContactFields: [
      'emailAddress', 'name', 'phoneNumber',
      'phoneticName', 'postalAddress'
    ],
    
    // supportedCountries: [ ... ],
    // billingContact: PaymentContact,
    // shippingContact: PaymentContact,
};

try {
  // See: https://developer.apple.com/documentation/passkit/pkpaymenttoken
  const { token } = await ApplePay.makePaymentRequest(paymentRequest);

  try {
    // INFO: Check and completion of the payment by your processing center
    await MyPaymentProvider.authorize(token.paymentData);

    ApplePay.completeLastTransaction({ status: 'success' });
  } catch {
    ApplePay.completeLastTransaction({ status: 'error' });
  }
} catch (e) {
  if (e.message === 'canceled') {
    // Payment widget was closed by user
  }
}

capacitor-apple-pay-new's People

Contributors

virusv avatar jonahelbaz 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.