Stripe Single Purchase

Stripe's single purchase code action functionality allows you to create a new raw product that can be purchased inside your flow or to use the price of the existing product.

This functionality also allows you to use key-value based metadata objects, which will be sent to your webhook along with payment information.

Usage Example

async payload => {
  const url = await payments.singlePurchase.stripe({
    secret: 'your_stripe_secret',
    key: 'your_stripe_publishable_key',
    collectAddress: true,
    locale: 'nl',
    submitType: 'auto',
    currency: 'usd',
    metadata: {
      MY_KEY: 'MY_VALUE'
    },
    items: [
      // raw products
      {
        price: 1200,
        quantity: 1,
        images: ['https://www.howtogeek.com/wp-content/uploads/2018/09/vac_lede.png'],
        name: 'Audio',
        description: 'Awesome mic'
      },
      {
        price: 1000,
        quantity: 2,
        images: ['https://www.howtogeek.com/wp-content/uploads/2018/09/vac_lede.png'],
        name: 'Video',
        description: 'Awesome cameras'
      },
      // existing product's price
      // PLEASE NOTE YOU CAN'T MIX RAW PRODUCTS WITH EXISTING PRICES
      {
        price: 'price_2XX7x0XXXyxxx6x9x7XxXXXx',
        quantity: 3
      }
    ],
    onSuccess: {
      eventName: 'bought',
      params: [
        new Param('name', 'electronics'),
        new Param('price', '21$')
      ]
    },
    onFailure: {
      eventName: 'not bought',
      params: [ new Param('name', 'electronics') ]
    }
  })
  
  const buttons = new Buttons('Purchase my items')
  buttons.addButton(new Button({
    label: 'Click to purchase',
    type: 'payment',
    value: url
  }))

  const message = new Message(`Purchase items here ${url}`)
  message.addResponse(buttons)

  return message
}

Properties

PropertyTypeExampleDescriptionRequired
secretstringsk_test_XXXXXXXXXXXYour Stripe Secret KeyYes
keystringpk_test_XXXXXXXXXXXYour Stripe Publishable KeyYes
collectAddressbooleantrueWhether Checkout should collect customer's addressNo
localestringnlBy default, Checkout detects the locale of the customer’s browser and displays a translated version of the page in their language if it is supported. You can also provide a specific locale for Checkout to use insteadNo
submitTypestringdonateSubmit the type of payment sessionNo
currencystringeurCurrency that should be used in checkoutYes
metadataobject{ MY_KEY: 'MY_VALUE' }The object that will be sent with payment details to your webhookNo
button.labelstringClick to PurchaseLabel of the confirmation buttonNo

Success and Failure params

You can include onSuccess and onFailure configurations that will be used in corresponding situations.

PropertyTypeExampleDescriptionRequired
eventNamestringboughtEvent name to trigger when items are successfully bought/purchased are rejectedNo
paramsarraynew Param('productiId', 112234)Parameters that are set when the items are bought/purchased are rejectedNo

Items

Multiple select is based on a purchase of several items. Each individual item should contain price, quantity and name properties and can contain images and description properties.

Properties

PropertyTypeExampleDescriptionRequired
pricenumber or string1000 or price_2XX7x0XXXyxxx6x9x7XxXXXxIf you're creating a new raw product, use numeric price (the last two digits correspond to .00)Yes
quantitynumber1Amount of items to be purchasedYes
imagesArray of strings["https://.../thumbnail.png"]URLs of images to display alongside corresponding product (if using with the raw product)No
namestringMicrophoneName of your productYes (if using with raw product)
description`string``Awesome micDescription of your product (if using with the raw product)No