npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jackobo/capacitor-apple-pay

v1.0.3

Published

Capacitor plugin for Apple Pay

Downloads

109

Readme

@jackobo/capacitor-apple-pay

Capacitor plugin for Apple Pay

Install

npm install @jackobo/capacitor-apple-pay
npx cap sync

Usage


async function payWithApplePay() {
    await CapacitorApplePay.addListener('validateMerchant', async (event: ValidateMerchantEvent) => {
        const merchantSession = await validateMerchantWithYourServer(event.validationURL);
            
        await CapacitorApplePay.completeMerchantValidation({
          merchantSession: merchantSession
        })
    });
    
    await CapacitorApplePay.addListener('authorizePayment', async (event: AuthorizePaymentEvent) => {
        try {
            const success = await processPaymentWithYourServer(event.payment);
            if(success) {
              await CapacitorApplePay.paymentAuthorizationSuccess();
            } else {
              await CapacitorApplePay.paymentAuthorizationFail();        
            }
        } finally {
            await CapacitorApplePay.removeAllListeners();
        }
    }
    
    await CapacitorApplePay.addListener('cancel', async () => {
        await CapacitorApplePay.removeAllListeners();
    });
    
    await CapacitorApplePay.startPayment(paymentRequestObject);
}

API

canMakePayments()

canMakePayments() => Promise<CanMakePaymentsResult>

Checks if Apple Pay is available

Returns: Promise<CanMakePaymentsResult>


addListener('validateMerchant', ...)

addListener(eventName: 'validateMerchant', handler: ValidateMerchantEventHandler) => Promise<PluginListenerHandle>

Subscribe to the validateMerchant event

| Param | Type | | --------------- | ------------------------------------------------------------------------------------- | | eventName | 'validateMerchant' | | handler | ValidateMerchantEventHandler |

Returns: Promise<PluginListenerHandle>


addListener('authorizePayment', ...)

addListener(eventName: 'authorizePayment', handler: AuthorizePaymentEventHandler) => Promise<PluginListenerHandle>

Subscribe to the authorizePayment event

| Param | Type | | --------------- | ------------------------------------------------------------------------------------- | | eventName | 'authorizePayment' | | handler | AuthorizePaymentEventHandler |

Returns: Promise<PluginListenerHandle>


addListener('cancel', ...)

addListener(eventName: 'cancel', handler: CancelPaymentEventHandler) => Promise<PluginListenerHandle>

Subscribe to the cancel event (when the payment is canceled by the user by closing Apple Pay payment sheet)

| Param | Type | | --------------- | ------------------------------------------------------------------------------- | | eventName | 'cancel' | | handler | CancelPaymentEventHandler |

Returns: Promise<PluginListenerHandle>


startPayment(...)

startPayment(request: PaymentRequest) => Promise<void>

Starts the payment process

| Param | Type | | ------------- | --------------------------------------------------------- | | request | PaymentRequest |


completeMerchantValidation(...)

completeMerchantValidation(request: CompleteMerchantValidationRequest) => Promise<void>

You call this from your code after you performed merchant validation with your server.

| Param | Type | | ------------- | ----------------------------------------------------------------------------------------------- | | request | CompleteMerchantValidationRequest |


paymentAuthorizationSuccess()

paymentAuthorizationSuccess() => Promise<void>

You call this from your code after the payment processing was successful


paymentAuthorizationFail()

paymentAuthorizationFail() => Promise<void>

You call this from your code after when the payment processing failed


removeAllListeners()

removeAllListeners() => Promise<void>

Unsubscribe from all events


Interfaces

CanMakePaymentsResult

Response returned by the canMakePayments method

| Prop | Type | Description | | --------------------- | -------------------- | ------------------------------------ | | canMakePayments | boolean | It is true if Apple Pay is available |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

ValidateMerchantEvent

The validateMerchant event payload

| Prop | Type | Description | | ------------------- | ------------------- | ----------------------------------------------------------------------------------------- | | validationURL | string | The URL that your backend needs to use in order to perform merchant validation with Apple |

AuthorizePaymentEvent

authorizePayment event payload

| Prop | Type | | ------------- | ---------------- | | payment | any |

PaymentRequest

The payload for startPayment method

| Prop | Type | | -------------------------- | ------------------------------------------------------------------- | | merchantId | string | | countryCode | string | | currencyCode | string | | supportedNetworks | PaymentNetwork[] | | merchantCapabilities | MerchantCapability[] | | total | PaymentRequestTotal |

PaymentRequestTotal

| Prop | Type | Description | | ------------ | --------------------------------- | ---------------------------------------------------------------------------- | | label | string | The text that appears next to the amount. Usually this is your merchant name | | amount | string | The amount formatted as string yourAmount.toFixed(2) | | type | 'final' | 'pending' | Defaults to final if not specified |

CompleteMerchantValidationRequest

completeMerchantValidation method request

| Prop | Type | Description | | --------------------- | ------------------- | ------------------------------------------------------------------------------------------ | | merchantSession | string | Contains the merchant session obtained from your server in the merchant validation process |

Type Aliases

ValidateMerchantEventHandler

validateMerchant event callback

(event: ValidateMerchantEvent): void

AuthorizePaymentEventHandler

authorizePayment event callback

(event: AuthorizePaymentEvent): void

CancelPaymentEventHandler

cancel event callback

(): void

PaymentNetwork

All available payment networks

'amex' | 'bancomat' | 'bancontact' | 'cartesBancaires' | 'chinaUnionPay' | 'dankort' | 'discover' | 'eftpos' | 'electron' | 'elo' | 'girocard' | 'interac' | 'jcb' | 'mada' | 'maestro' | 'masterCard' | 'mir' | 'privateLabel' | 'visa' | 'vPay'

MerchantCapability

Merchant capabilities

'supports3DS' | 'supportsCredit' | 'supportsDebit' | 'supportsEMV'