This function also allows you to use key-value based metadata
object that will be sent to your webhook alongside with 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
Property | Type | Example | Description | Required |
---|---|---|---|---|
secret |
string |
sk_test_XXXXXXXXXXX | Your Stripe Secret Key | Yes |
key |
string |
pk_test_XXXXXXXXXXX | Your Stripe Publishable Key | Yes |
collectAddress |
boolean |
true | Whether Checkout should collect customer's address | |
locale |
string |
nl | By 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 | |
submitType |
string |
donate | Submit type of payment session | |
currency |
string |
eur | Currency that should be used in checkout | Yes |
metadata |
object |
{ MY_KEY: 'MY_VALUE' } | Object that will be sent with payment details to your webhook | |
button.label |
string |
Click to purchase | Label of the confirmation button |
Success and Failure params
You can include onSuccess
and onFailure
configuration which will be used in corresponding situations.
Property | Type | Example | Description | Required |
---|---|---|---|---|
eventName |
string |
bought | Event name to trigger when items are successfully bought / purchase is rejected | |
params |
array |
new 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
Property | Type | Example | Description | Required |
---|---|---|---|---|
price |
number or string |
1000 or price_2XX7x0XXXyxxx6x9x7XxXXXx |
If you're creating new raw product you need to use numeric price (last two digits correspond to .00) | Yes |
quantity |
number |
1 | Amount of items to be purchased | Yes |
images |
Array of strings |
["https://.../thumbnail.png"] |
URLs of images to display alongside corresponding product (if using with raw product) | |
name |
string |
Microphone | Name of your product | Yes (if using with raw product) |
description |
string |
Awesome mic | Description of your product (if using with raw product) |