> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: createPayment(paymentInfo: PaymentInfo) # Method package: wixPayBackend # Method menu location: wixPayBackend --> createPayment # Method Link: https://dev.wix.com/docs/velo/apis/wix-pay-backend/create-payment.md # Method Description: Creates a new payment. Before using the createPayment() function, you need to set up your site to accept payments. To learn more, see [About Accepting Payments](https://support.wix.com/en/article/about-accepting-payments). When setting up your site to accept payments, be sure to select the payment methods you want to offer and [set your payment currency](https://support.wix.com/en/article/setting-your-currency-for-accepting-payments). The `createPayment()` function returns a Promise that resolves to a `Payment` object when the payment has been created. Creating a payment is the first step in the process of accepting a payment from a user. After creating the payment, call [`startPayment()`](wix-pay-frontend/start-payment) from your site's client-side code using the payment ID returned by `createPayment`. The [`startPayment()`](wix-pay-frontend/start-payment) function prompts the user to select a payment method and continue the payment process. To understand how `createPayment()` is used in a typical payment lifecycle, see [Typical Payment Lifecycle](wix-pay-backend/introduction#typical-payment-lifecycle). > **Note:** > - To work with the Pay API, you need to save and publish your site. > - For security reasons you should always create the `PaymentInfo` object in backend code. Do not pass payment information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change payment information, such as the price of an item being purchased. > - To learn more about how to keep your payment code secure, see [Security Considerations When Working with Wix Code](https://support.wix.com/en/article/security-considerations-when-working-with-wix-code#code-visibility). # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Create a new payment ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixPayBackend from 'wix-pay-backend'; export function createMyPayment() { return wixPayBackend.createPayment({ items: [{ name: "Product Name", price: 9.99 }], amount: 9.99 }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { createMyPayment() .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ## Create a new payment using quantity ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixPayBackend from 'wix-pay-backend'; export function createMyPayment() { return wixPayBackend.createPayment({ items: [{ name: "Product Name", price: 9.99, quantity: 2 }], amount: 19.98 }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { createMyPayment() .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ## Create a new payment with user information ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixPayBackend from 'wix-pay-backend'; export function createMyPayment(userInfo) { return wixPayBackend.createPayment({ items: [{ name: "Product Name", price: 9.99, quantity: 2 }], amount: 19.98, userInfo }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { const firstName = // the user's first name const lastName = // the user's last name const phone = // the user's phone number const email = // the user's email address const countryCode = // the user's country code createMyPayment({ firstName, lastName, phone, email, countryCode }) .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ## Create a new payment with custom currency ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixPayBackend from 'wix-pay-backend'; export function createMyPayment() { return wixPayBackend.createPayment({ items: [{ name: "Product Name", price: 9.99 }], amount: 9.99, currency: "USD" }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { createMyPayment() .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ## Create a new payment using collection data ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixData from 'wix-data'; import wixPayBackend from 'wix-pay-backend'; export async function createMyPayment(productId) { return wixData.get("productCollection", productId) .then((product) => { return wixPayBackend.createPayment({ items: [{ name: product.name, price: product.price }], amount: product.price }); }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { createMyPayment(event.context.itemId) .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ## Create a new payment using collection data and a quantity ```javascript /************************** * Backend code - pay.jsw * **************************/ import wixData from 'wix-data'; import wixPayBackend from 'wix-pay-backend'; export async function createMyPayment(productId) { return wixData.get("productCollection", productId) .then((product) => { return wixPayBackend.createPayment({ items: [{ name: product.name, price: product.price }], amount: product.price }); }); } /******************** * Client-side code * ********************/ import { createMyPayment } from 'backend/pay'; import wixPay from 'wix-pay'; export function myButton_click(event, $w) { createMyPayment(event.context.itemId) .then((payment) => { wixPay.startPayment(payment.id); }); } ``` ---