0.0.4 • Published 4 months ago

@projektionisten/capacitor-braintree v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@projektionisten/capacitor-braintree

Braintree is a payment platform many developers use to facilitate specifically paypal payments in their apps, but other payment methods like Google/Apple Pay and credit cards are available through the Braintree SDK. This Capacitor plugin is meant to provide ways to use that SDK for different platforms through a web app

Install

NPM

npm i @projektionisten/capacitor-braintree
npx cap sync

YARN

yarn add @projektionisten/capacitor-braintree
npx cap sync

Android

For the paypal browser flow to work, you need to add this overload to the MainActivity of your android project

@Override
protected void onNewIntent(Intent newIntent) {
    super.onNewIntent(newIntent);

    setIntent(newIntent);
}

Also, an intent-filter for returning into the app needs to be defined. The ${applicationId} does not need to be replaced by anything, it automatically inserts the package name of the application

Beware: If your package name includes special characters like an _underscore, the intent filter is not going to work and you have to replace ${applicationId} with a version of your package name with the special characters removed. For example, if your package name is com.package_name.example, the scheme would have to be com.packagename.example.braintree

<intent-filter >
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="${applicationId}.braintree" />
</intent-filter>

If you want to enable GooglePay, you also need to add this meta tag to the application element in your Manifest file

<meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true"/>

API

setClientToken(...)

setClientToken(options: TokenOptions) => Promise<void>

This updates the plugin with a new auth token.

This needs to be called before the SDK can be used.

ParamType
optionsTokenOptions

startPaypalPayment(...)

startPaypalPayment(options: PaypalPaymentOptions) => Promise<PaymentUIResult>

Starts a transaction with the paypal sdk. Will open a seperate browser window or similar to complete and return with information about the used account and the payment nonce

ParamType
optionsPaypalPaymentOptions

Returns: Promise<PaymentUIResult>


startApplePayPayment(...)

startApplePayPayment(options: ApplePaymentOptions) => Promise<PaymentUIResult>

Starts a transaction with the apple pay sdk. Will open a seperate browser window or similar to complete and return with information about the used account and the payment nonce

ParamType
optionsApplePaymentOptions

Returns: Promise<PaymentUIResult>


startGooglePayPayment(...)

startGooglePayPayment(options: GooglePaymentOptions) => Promise<PaymentUIResult>

Starts a transaction with the google pay sdk. Will open a seperate browser window or similar to complete and return with information about the used account and the payment nonce

ParamType
optionsGooglePaymentOptions

Returns: Promise<PaymentUIResult>


isGooglePayReady()

isGooglePayReady() => Promise<PaymentMethodReadyResult>

Google pay specifically offers a method to wait for it to be ready to use. Returns a promise that resolves when it is ready.

Returns: Promise<PaymentMethodReadyResult>


isApplePayReady()

isApplePayReady() => Promise<PaymentMethodReadyResult>

Check if apple pay is available on this device

Returns: Promise<PaymentMethodReadyResult>


Interfaces

TokenOptions

Options for setting up payment tokens

PropTypeDescriptionDefault
tokenstringThe token to be used
env'development' | 'production'Environment for the payment providers. Currently only used by the google pay client in the *WEBimplementation. When env is 'development', the google pay client will use the TEST config, accessing only the sandbox.'production'

PaymentUIResult

Successful callback result for the payment methods.

PropTypeDescription
userCancelledbooleanIndicates if the user used the cancel button to close the dialog without completing the payment.
noncestringThe nonce for the payment transaction (if a payment was completed).
typestringThe payment type (if a payment was completed).
localizedDescriptionstringA description of the payment method (if a payment was completed).
card{ lastTwo: string; network: CREDIT_CARD_NETWORK; }Information about the credit card used to complete a payment (if a credit card was used).
paypalAccount{ email: string; firstName?: string; lastName?: string; phone?: string; billingAddress?: string; shippingAddress?: string; clientMetadataId?: string; payerId?: string; }Information about the PayPal account used to complete a payment (if a PayPal account was used).
threeDSecureCard{ liabilityShifted: boolean; liabilityShiftPossible: boolean; }Information about 3D Secure card used to complete a payment (if 3D Secure was used).

PaypalPaymentOptions

Options for the payment methods.

PropTypeDescriptionDefault
amountstringThe amount of the transaction to show in the drop-in UI on the summary row as well as the call to action button.
primaryDescriptionstringThe description of the transaction to show in the drop-in UI on the summary row.
paymentFlowPAYPAL_PAYMENT_FLOWType of payment flow. Either an one-time checkout or a vaulted payment, for easier transactions in the futurePAYPAL_PAYMENT_FLOW.CHECKOUT
userActionPAYPAL_USER_ACTIONDefines the type of call to action button the user clicks to return to the shop. By default, the call to action button will imply that there is a checkout with a final price after the user authorization. Use PAYPAL_USER_ACTION.COMMIT if it should be a final "pay now" button.PAYPAL_USER_ACTION.CONTINUE_TO_CHECKOUT

ApplePaymentOptions

Options for the payment methods.

PropTypeDescriptionDefault
amountstringThe amount of the transaction to show in the drop-in UI on the summary row as well as the call to action button.
currencyCodestringISO 4217 code of the currency used, like 'EUR' or 'USD''EUR'
countryCodestringISO 3166 code of the merchants country, like 'DE' or 'US'. Defaults to the settings in your braintree backend
primaryDescriptionstringThe description of the transaction to show in the drop-in UI on the summary row.

GooglePaymentOptions

Options for the payment methods.

PropTypeDescriptionDefault
merchantIdstringMerchant ID to use for this transaction if it differs from the one in your braintree account
amountstringThe amount of the transaction to show in the drop-in UI on the summary row as well as the call to action button.
amountStatus'ESTIMATED' | 'FINAL'Is the price already the final one to be paid, or will potential sales taxes or shipping prices be added later in the checkout'FINAL'
currencyCodestringISO 4217 code of the currency used, like 'EUR' or 'USD''EUR'

PaymentMethodReadyResult

Result for a method that checks if a given payment method is ready to be used

PropType
readyboolean

Enums

CREDIT_CARD_NETWORK

MembersValue
UNKNOWN'BTCardNetworkUnknown'
AMEX'BTCardNetworkAMEX'
DINERS_CLUB'BTCardNetworkDinersClub'
DISCOVER'BTCardNetworkDiscover'
MASTER_CARD'BTCardNetworkMasterCard'
VISA'BTCardNetworkVisa'
JCB'BTCardNetworkJCB'
LASER'BTCardNetworkLaser'
MAESTRO'BTCardNetworkMaestro'
UNION_PAY'BTCardNetworkUnionPay'
SOLO'BTCardNetworkSolo'
SWITCH'BTCardNetworkSwitch'
UK_MAESTRO'BTCardNetworkUKMaestro'

PAYPAL_PAYMENT_FLOW

MembersValue
CHECKOUT'checkout'
VAULT'vault'

PAYPAL_USER_ACTION

MembersValue
CONTINUE_TO_CHECKOUT'continue'
COMMIT'commit'
0.0.4

4 months ago

0.0.3

4 months ago

0.0.3-dev1

4 months ago