결제 스크립트 예제
결제 스크립트는 전자결제 대행사와 상호 작용하며 전자결제 대행사의 이름, 표시 유형 및 표시 위치를 변경할 수 있습니다. 이 스크립트에서는 고객이 결제 시 결 제 방법 페이지에 액세스할 때마다 실행됩니다. 빠른 결제는 고객이 결제 페이지에 도달하기 전에 표시되기 때문에 결제 스크립트는 빠른 결제 와 상호 작용하지 않습니다.
플랜 요구 사항
Shopify Scripts 및 Script Editor 앱은 Shopify Plus 플랜을 이용하는 스토어만 사용할 수 있습니다. Script Editor 앱은 더 이상 Shopify App Store에서 다운로드할 수 없습니다.
2025년 8월 28일부터 Shopify Scripts가 제거되고 더 이상 작동하지 않습니다. 이 날짜 전에 기존 스크립트를 Shopify Functions 로 마이그레이션하십시오.
이 페이지의 템플릿을 사용하려면 빈 템플릿으로 새 스크립트를 만드십시오.
단계:
Shopify Admin에서 앱 > Script Editor 로 이동합니다.
스크립트 생성 을 클릭합니다.
전자결제 대행사 를 클릭합니다.
빈 템플릿 을 선택하고 스크립트 생성 을 클릭합니다.
Ruby 소스 코드 섹션에서 기본 코드 라인을 삭제합니다. Output.cart = Input.cart
이 페이지에서 스크립트를 복사하여 Ruby 소스 코드 섹션에 붙여넣습니다.
스크립트의 사용자 지정 가능 설정 섹션을 편집하여 스토어에서 작동시킵니다.
스크립트를 테스트합니다. 자세한 내용은 Shopify Scripts 테스트 및 디버그 를 참조하십시오.
테스트 후에는
초안 저장 을 클릭하여 해당 스크립트의 게시되지 않은 초안을 저장하거나
저장 및 게시 를 클릭하여 스크립트를 생성하고 게시합니다.
특정 고객에게 게이트웨이 표시 이 스크립트를 사용하여 특별한 태그가 지정된 고객에게만 특정 게이트웨이 옵션을 표시합니다.
예를 들어, VIP
태그가 지정된 고객에게만 특정 게이트웨이를 표시하면 다른 고객에게는 게이트웨이가 숨겨집니다.
# ================================ Customizable Settings ================================
# ================================================================
# Show Gateways For Customer Tag
#
# If we have a matching customer, the entered gateway(s) will be
# shown, and all others will be hidden. Otherwise, the entered
# gateway(s) will be hidden.
#
# - 'customer_tag_match_type' determines whether we look for the customer
# to be tagged with any of the entered tags or not. Can be:
# - ':include' to check if the customer is tagged
# - ':exclude' to make sure the customer isn't tagged
# - 'customer_tags' is a list of customer tags to trigger the
# campaign
# - 'gateway_match_type' determines whether the below strings
# should be an exact or partial match. Can be:
# - ':exact' for an exact match
# - ':partial' for a partial match
# - 'gateway_names' is a list of strings to identify gateways
# ================================================================
SHOW_GATEWAYS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include ,
customer_tags: [ "customer_tag" , "another_tag" ],
gateway_match_type: :exact ,
gateway_names: [ "Gateway" , "Other Gateway" ],
},
]
# ================================ Script Code (do not edit) ================================
# ================================================================
# CustomerTagSelector
#
# Finds whether the supplied customer has any of the entered tags.
# ================================================================
class CustomerTagSelector
def initialize ( match_type , tags )
@comparator = match_type == :include ? 'any?' : 'none?'
@tags = tags . map { | tag | tag . downcase . strip }
end
def match? ( customer )
customer_tags = customer . tags . map { | tag | tag . downcase . strip }
( @tags & customer_tags ). send ( @comparator )
end
end
# ================================================================
# GatewayNameSelector
#
# Finds whether the supplied gateway name matches any of the
# entered names.
# ================================================================
class GatewayNameSelector
def initialize ( match_type , gateway_names )
@comparator = match_type == :exact ? '==' : 'include?'
@gateway_names = gateway_names . map { | name | name . downcase . strip }
end
def match? ( payment_gateway )
@gateway_names . any? { | name | payment_gateway . name . downcase . strip . send ( @comparator , name ) }
end
end
# ================================================================
# ShowGatewaysForCustomerTagCampaign
#
# If the customer has any of the entered tags, the entered gateways
# are shown/hidden depending on the entered settings
# ================================================================
class ShowGatewaysForCustomerTagCampaign
def initialize ( campaigns )
@campaigns = campaigns
end
def run ( cart , payment_gateways )
@campaigns . each do | campaign |
customer_tag_selector = CustomerTagSelector . new (
campaign [ :customer_tag_match_type ],
campaign [ :customer_tags ],
)
customer_match = cart . customer . nil? ? false : customer_tag_selector . match? ( cart . customer )
gateway_name_selector = GatewayNameSelector . new (
campaign [ :gateway_match_type ],
campaign [ :gateway_names ],
)
payment_gateways . delete_if do | payment_gateway |
gateway_name_selector . match? ( payment_gateway ) != customer_match
end
end
end
end
CAMPAIGNS = [
ShowGatewaysForCustomerTagCampaign . new ( SHOW_GATEWAYS_FOR_CUSTOMER_TAG ),
]
CAMPAIGNS . each do | campaign |
campaign . run ( Input . cart , Input . payment_gateways )
end
Output . payment_gateways = Input . payment_gateways
특정 고객에게 게이트웨이 숨기기 이 스크립트를 사용하여 특별한 태그가 지정된 고객에게 특정 게이트웨이를 숨길 수 있습니다.
예를 들어, HIDE_GATEWAY
태그가 지정된 고객에게 특정 게이트웨이를 숨깁니다.
# ================================ Customizable Settings ================================
# ================================================================
# Hide Gateways For Customer Tag
#
# If we have a matching customer, the entered gateway(s) will be
# hidden.
#
# - 'customer_tag_match_type' determines whether we look for the customer
# to be tagged with any of the entered tags or not. Can be:
# - ':include' to check if the customer is tagged
# - ':exclude' to make sure the customer isn't tagged
# - 'customer_tags' is a list of customer tags to trigger the
# campaign
# - 'gateway_match_type' determines whether the below strings
# should be an exact or partial match. Can be:
# - ':exact' for an exact match
# - ':partial' for a partial match
# - 'gateway_names' is a list of strings to identify gateways
# ================================================================
HIDE_GATEWAYS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include ,
customer_tags: [ "customer_tag" , "another_tag" ],
gateway_match_type: :exact ,
gateway_names: [ "Gateway" , "Other Gateway" ],
},
]
# ================================ Script Code (do not edit) ================================
# ================================================================
# CustomerTagSelector
#
# Finds whether the supplied customer has any of the entered tags.
# ================================================================
class CustomerTagSelector
def initialize ( match_type , tags )
@comparator = match_type == :include ? 'any?' : 'none?'
@tags = tags . map { | tag | tag . downcase . strip }
end
def match? ( customer )
customer_tags = customer . tags . map { | tag | tag . downcase . strip }
( @tags & customer_tags ). send ( @comparator )
end
end
# ================================================================
# GatewayNameSelector
#
# Finds whether the supplied gateway name matches any of the
# entered names.
# ================================================================
class GatewayNameSelector
def initialize ( match_type , gateway_names )
@comparator = match_type == :exact ? '==' : 'include?'
@gateway_names = gateway_names . map { | name | name . downcase . strip }
end
def match? ( payment_gateway )
@gateway_names . any? { | name | payment_gateway . name . downcase . strip . send ( @comparator , name ) }
end
end
# ================================================================
# HideGatewaysForCustomerTagCampaign
#
# If we have a matching customer, the entered gateway(s) will be
# hidden.
# ================================================================
class HideGatewaysForCustomerTagCampaign
def initialize ( campaigns )
@campaigns = campaigns
end
def run ( cart , payment_gateways )
return if cart . customer . nil?
@campaigns . each do | campaign |
customer_tag_selector = CustomerTagSelector . new (
campaign [ :customer_tag_match_type ],
campaign [ :customer_tags ],
)
next unless customer_tag_selector . match? ( cart . customer )
gateway_name_selector = GatewayNameSelector . new (
campaign [ :gateway_match_type ],
campaign [ :gateway_names ],
)
payment_gateways . delete_if do | payment_gateway |
gateway_name_selector . match? ( payment_gateway )
end
end
end
end
CAMPAIGNS = [
HideGatewaysForCustomerTagCampaign . new ( HIDE_GATEWAYS_FOR_CUSTOMER_TAG ),
]
CAMPAIGNS . each do | campaign |
campaign . run ( Input . cart , Input . payment_gateways )
end
Output . payment_gateways = Input . payment_gateways
특정 제품에 대한 게이트웨이 숨기기 특정 품목이 카트에 추가되면 이 스크립트를 사용하여 특정 게이트웨이를 숨길 수 있습니다.
예를 들어 고객이 모자를 주문하는 경우 특정 게이트웨이를 숨길 수 있습니다.
# ================================ Customizable Settings ================================
# ================================================================
# Hide Gateway(s) for Product
#
# If the cart contains any matching items, the entered gateway(s)
# are hidden.
#
# - 'product_selector_match_type' determines whether we look for
# products that do or don't match the entered selectors. Can
# be:
# - ':include' to check if the product does match
# - ':exclude' to make sure the product doesn't match
# - 'product_selector_type' determines how eligible products
# will be identified. Can be either:
# - ':tag' to find products by tag
# - ':type' to find products by type
# - ':vendor' to find products by vendor
# - ':product_id' to find products by ID
# - ':variant_id' to find products by variant ID
# - ':subscription' to find subscription products
# - 'product_selectors' is a list of strings or numbers to
# identify products by the above selector type
# - 'gateway_match_type' determines whether the below strings
# should be an exact or partial match. Can be:
# - ':exact' for an exact match
# - ':partial' for a partial match
# - 'gateway_names' is a list of strings to identify gateways
# ================================================================
HIDE_GATEWAY_FOR_PRODUCT = [
{
product_selector_match_type: :include ,
product_selector_type: :product_id ,
product_selectors: [ 1234567890987 , 1234567890986 ],
gateway_match_type: :exact ,
gateway_names: [ "Gateway" , "Other Gateway" ],
},
]
# ================================ Script Code (do not edit) ================================
# ================================================================
# ProductSelector
#
# Finds matching products by the entered criteria.
# ================================================================
class ProductSelector
def initialize ( match_type , selector_type , selectors )
@match_type = match_type
@comparator = match_type == :include ? 'any?' : 'none?'
@selector_type = selector_type
@selectors = selectors
end
def match? ( line_item )
if self . respond_to? ( @selector_type )
self . send ( @selector_type , line_item )
else
raise RuntimeError . new ( 'Invalid product selector type' )
end
end
def tag ( line_item )
product_tags = line_item . variant . product . tags . map { | tag | tag . downcase . strip }
@selectors = @selectors . map { | selector | selector . downcase . strip }
( @selectors & product_tags ). send ( @comparator )
end
def type ( line_item )
@selectors = @selectors . map { | selector | selector . downcase . strip }
( @match_type == :include ) == @selectors . include? ( line_item . variant . product . product_type . downcase . strip )
end
def vendor ( line_item )
@selectors = @selectors . map { | selector | selector . downcase . strip }
( @match_type == :include ) == @selectors . include? ( line_item . variant . product . vendor . downcase . strip )
end
def product_id ( line_item )
( @match_type == :include ) == @selectors . include? ( line_item . variant . product . id )
end
def variant_id ( line_item )
( @match_type == :include ) == @selectors . include? ( line_item . variant . id )
end
def subscription ( line_item )
! line_item . selling_plan_id . nil?
end
end
# ================================================================
# GatewayNameSelector
#
# Finds whether the supplied gateway name matches any of the
# entered names.
# ================================================================
class GatewayNameSelector
def initialize ( match_type , gateway_names )
@comparator = match_type == :exact ? '==' : 'include?'
@gateway_names = gateway_names . map { | name | name . downcase . strip }
end
def match? ( payment_gateway )
@gateway_names . any? { | name | payment_gateway . name . downcase . strip . send ( @comparator , name ) }
end
end
# ================================================================
# HideGatewayForProductCampaign
#
# If the cart contains any matching items, the entered gateway(s)
# are hidden.
# ================================================================
class HideGatewayForProductCampaign
def initialize ( campaigns )
@campaigns = campaigns
end
def run ( cart , payment_gateways )
@campaigns . each do | campaign |
product_selector = ProductSelector . new (
campaign [ :product_selector_match_type ],
campaign [ :product_selector_type ],
campaign [ :product_selectors ],
)
next unless cart . line_items . any? { | line_item | product_selector . match? ( line_item ) }
gateway_name_selector = GatewayNameSelector . new (
campaign [ :gateway_match_type ],
campaign [ :gateway_names ],
)
payment_gateways . delete_if do | payment_gateway |
gateway_name_selector . match? ( payment_gateway )
end
end
end
end
CAMPAIGNS = [
HideGatewayForProductCampaign . new ( HIDE_GATEWAY_FOR_PRODUCT ),
]
CAMPAIGNS . each do | campaign |
campaign . run ( Input . cart , Input . payment_gateways )
end
Output . payment_gateways = Input . payment_gateways
특정 국가에 대한 게이트웨이 표시 고객이 특정 국가에서 주문하는 경우 이 스크립트를 사용하여 특정 게이트웨이만 표시합니다.