Payment scripts interact with payments, and can rename, hide and reorder payment gateways. Note that payment scripts do not interact with payment gateways shown before the checkout screen, such as Apple Pay. These scripts are run when the checkout reaches the payment page.

General methods

Input

Cart

The cart object is only available on the Online Store and JS Buy SDK channels. Some abandoned checkouts have access to the cart object. However, if a checkout has been closed and then a customer visits the abandoned checkout, it sends them to the pre-filled checkout and the cart object will no longer exist. This is because the storefront has been bypassed by the abandoned checkout email.

discount_code is present if a discount has been applied to the cart. This does not necessarily mean that the price of the cart changes. For example, if a discount applies to carts above $50, and a script reduces the cart price below $50, discount_code is still present but the price of the cart doesn't change.

Money

Converts an amount (in cents) from the customer's local (presentment) currency to your store's currency. This method accepts the customer_cents parameter, which accepts a number in cents. For example, Money.derived_from_presentment(customer_cents: 500). This method is part of selling in multiple currencies, which is currently in beta for Shopify Plus plans.

Product

Returns a list of strings representing the tags that are set for this product.

.product_type

String

A categorization that a product can be tagged with, commonly used for filtering and searching.

.vendor

String

Returns the vendor of this product.

Kernel

Kernel is a Ruby module that is included in every class. As a result, its methods are available to every object. These methods act in the same way as global functions act in other languages.

Method

Return type

Description

.exit

none

Ends execution of the current script without error. If this is run before anything is assigned to Output.cart, the script has no effect. This is a useful way to exit scripts, for example, if the customer is ineligible to run the script.

Kernel example

customer=Input.cart.customerifcustomer&&customer.email.end_with?("@mycompany.com")# Employees are not eligible for this promotion.exitend

Splits a line item into two line items. take specifies what quantity to remove from the original line item to create the new line item.

.split example

This example script splits a line item called original_line_item into two line items. The new line item has a quantity of 1 (specified by take: 1). The script then applies a discounted price to the new line item with the message "Third hat for 5 dollars".

PaymentGateway

If the payment gateway supports credit cards, returns a list of the credit card types allowed by the store. If the gateway doesn't support credit cards, returns an empty list.

.change_name(String new_name)

String

Changes the name of the payment gateway.

Examples

In the following line item script example, when a customer orders a product that is not a gift card, then the price of the product is reduced by $9. Also, the total amount that the customer has spent throughout all visits to your store is shown: