Stripe Single Purchase

This code action function allows you to create a new raw product that can be purchased inside your flow or you can use price of the existing product.
This function also allows you to use key-value based metadata object that will be sent to your webhook alongside payment details.

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 address
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 instead
submitTypestringdonateSubmit type of payment session
currencystringeurCurrency that should be used in checkoutYes
metadataobject{ MY_KEY: 'MY_VALUE' }Object that will be sent with payment details to your webhook
button.labelstringClick to PurchaseLabel of the confirmation button

Success and Failure params

You can include onSuccess and onFailure configuration which will be used in corresponding situations.

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

Items

The multiple select is based on a number of 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 new raw product you need to use numeric price (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 raw product)
namestringMicrophoneName of your productYes (if using with raw product)
description`string``Awesome micDescription of your product (if using with raw product)