Skip to main content

Push JS SDK Reference

The SDK must be loaded as a script tag on your website — it cannot be statically bundled via package management.
<script src="https://cdn.pushcash.com/sdk/push.umd.js"></script>

Widget

new window.PushCash.Widget(options)

Creates and renders the Push User Widget into your page to receive card details from a user.

Options (WidgetOptions)

FieldTypeRequiredDescription
selectorstringCSS selector for the container element to render into.
urlstringWidget URL returned from create-widget-url.
onValid() => voidCalled once the widget has received valid card details. Use to enable the submit button.
backgroundstringWidget background (CSS color value).
fontSizestringBase font size (CSS value, e.g. 14px).
borderRadiusstringCorner radius (CSS value, e.g. 12px).
paddingstringInner padding (CSS value, e.g. 16px).
colorstringText color (CSS color value).

Returns

A Widget instance.

Example

const widget = new window.PushCash.Widget({
  selector: '#payment-container',
  url: 'https://cdn.pushcash.com/widget/?param=1&param=2',
  onValid: () => { console.log('user has provided valid card details') },
  background: '#ffffff',
  fontSize: '16px',
  borderRadius: '8px',
  padding: '12px',
  color: '#000000',
});

widget.tokenize()

Generates a token from the user’s card details which can be used to authorize a transaction on the user’s card by calling authorize-payment. If the tokenize function is called before the user has provided valid card details, will throw an error. Signature
tokenize: () => Promise<{ token: string }>
Example
try {
  const { token } = await widget.tokenize();
} catch (error) {
  console.error(User has not provided valid card details, error returned from tokenize call:', error)
}

widget.destroy()

Unmounts the widget and cleans up resources. Signature
destroy: () => void

Apple Pay Launcher

new window.PushCash.ApplePay(config)

Creates an Apple Pay launcher instance.

Parameters

FieldTypeRequiredDescription
tokenstringApple Pay token returned from create-token with type: "apple_pay". Must be newly created per page load.

Example

const launcher = new window.PushCash.ApplePay({
  token: '<apple-pay-token>',
});

launcher.display(args)

Launches the Apple Pay payment sheet and runs the Apple Pay flow.

Parameters

FieldTypeRequiredDescription
amountnumberPayment amount in cents (must be > 0).
direction'cash_in'Only cash_in is supported.
currency'USD'Only "USD" is supported.
onStart() => Promise<void>Called during the presentation of the payment sheet to the user. Use this to create a payment intent with type: "apple_pay" and the apple pay token.
onComplete() => void | Promise<void>Called when the Apple Pay session completes.

Example

launcher.display({
  amount: 1000,
  direction: 'cash_in',
  currency: 'USD',
  onStart: async () => {
    // call backend to create payment intent via Push API
  },
  onComplete: () => {
    // call backend to fetch and determine payment status
  },
});