Build a payment script
In this tutorial, you’ll learn how to create a basic payment script and deploy it to a custom app.
What you'll learn
After you've finished this tutorial, you'll have accomplish the following:
- Created a basic payment script using Shopify CLI
- Deployed your script to the Shopify platform and associated it with a custom app
- Enabled the script in a Shopify store
- Placed a test order in your store to confirm your script is working as expected
The following diagram shows the steps you'll follow to complete the workflow:
- You've installed Shopify CLI.
- You've created a custom app. Shopify Scripts currently only supports custom apps.
- You've installed the custom app on a store.
Step 1: Create the script
Using Shopify CLI, run the following command:
Update the payment script
Replace the contents of your payment script in
src/script.ts with the code below.
paymentMethodsHandler runs when a customer reaches the payment page of checkout. The results of this function are the sort order, payment methods to remove, or payment methods to rename.
Step 2: Deploy the script
To deploy a script to the Shopify platform and associate it with a custom app, run the following command:
Step 3: Enable the script
By default, scripts are available to be used on a store with the app installed, but they aren't enabled. To alter the behavior of checkout, you need to enable the script:
- In your store's Shopify admin, click Settings.
- Click Payments.
- In the Payment method customizations section, click Create customization.
- Select the script to enable and update its status to On.
- Click Save.
Step 4: Place a test order
Place a test order in your store and go through the checkout steps. The payment methods shown at the payment step should show Renamed by scripts: