Skip to content

Commit 299102f

Browse files
authored
Merge pull request #619 from Shopify/mg/04-28-update_payment_customization_function_templates
Update Payment Customization function templates
2 parents 899ceeb + 719e0db commit 299102f

15 files changed

Lines changed: 468 additions & 96 deletions

checkout/javascript/payment-customization/default/schema.graphql

Lines changed: 131 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ type CartLineCost {
328328
totalAmount: MoneyV2!
329329
}
330330

331+
"""
332+
The `CartPaymentMethodsTransformRunResult` object is the output of the Function
333+
run target. The object contains the operations to apply to payment methods in checkout.
334+
"""
335+
input CartPaymentMethodsTransformRunResult {
336+
"""
337+
The ordered list of operations to apply to the list of payment methods.
338+
"""
339+
operations: [Operation!]!
340+
}
341+
331342
"""
332343
Whether the product is in the specified collection.
333344
@@ -2778,6 +2789,45 @@ enum DeliveryMethod {
27782789
SHIPPING
27792790
}
27802791

2792+
"""
2793+
An operation to apply to the list of payment methods.
2794+
"""
2795+
input DeprecatedOperation @oneOf {
2796+
"""
2797+
A request to hide a payment method during checkout.
2798+
2799+
When your Function returns this operation, it removes the specified payment method
2800+
from the available options shown to customers during checkout.
2801+
2802+
Use this operation when you want to conditionally hide payment methods based on
2803+
checkout attributes, customer data, or other business logic implemented in your Function.
2804+
"""
2805+
hide: HideOperation @deprecated(reason: "Use `paymentMethodHide` instead.")
2806+
2807+
"""
2808+
A request to move a payment method to a new position in the checkout display order.
2809+
2810+
When your Function returns this operation, it changes the display order of payment methods
2811+
by placing the specified payment method at the requested index position.
2812+
2813+
Use this operation when you want to prioritize certain payment methods based on
2814+
checkout context, customer preferences, or other business logic implemented in your Function.
2815+
"""
2816+
move: MoveOperation @deprecated(reason: "Use `paymentMethodMove` instead.")
2817+
2818+
"""
2819+
A request to change the displayed name of a payment method during checkout.
2820+
2821+
When your Function returns this operation, it replaces the default name of the
2822+
specified payment method with the custom name that's provided in the request.
2823+
2824+
Use this operation when you want to provide more context or clarity about
2825+
payment methods based on checkout details, locale, or other business logic
2826+
implemented in your Function.
2827+
"""
2828+
rename: RenameOperation @deprecated(reason: "Use `paymentMethodRename` instead.")
2829+
}
2830+
27812831
"""
27822832
The output of the Function run target. The object contains the operations to
27832833
apply to payment methods in checkout. In API versions 2023-10 and beyond, this
@@ -2787,7 +2837,7 @@ input FunctionResult {
27872837
"""
27882838
The ordered list of operations to apply to the list of payment methods.
27892839
"""
2790-
operations: [Operation!]!
2840+
operations: [DeprecatedOperation!]!
27912841
}
27922842

27932843
"""
@@ -2797,7 +2847,7 @@ input FunctionRunResult {
27972847
"""
27982848
The ordered list of operations to apply to the list of payment methods.
27992849
"""
2800-
operations: [Operation!]!
2850+
operations: [DeprecatedOperation!]!
28012851
}
28022852

28032853
"""
@@ -3772,7 +3822,7 @@ type Localization {
37723822
"""
37733823
The market of the active localized experience.
37743824
"""
3775-
market: Market!
3825+
market: Market! @deprecated(reason: "This `market` field will be removed in a future version of the API.")
37763826
}
37773827

37783828
"""
@@ -4040,7 +4090,7 @@ type MailingAddress {
40404090
"""
40414091
The market of the address.
40424092
"""
4043-
market: Market
4093+
market: Market @deprecated(reason: "This `market` field will be removed in a future version of the API.")
40444094

40454095
"""
40464096
The full name of the customer, based on firstName and lastName.
@@ -4220,6 +4270,16 @@ input MoveOperation {
42204270
The root mutation for the API.
42214271
"""
42224272
type MutationRoot {
4273+
"""
4274+
Handles the Function result for the cart.payment-methods.transform.run target.
4275+
"""
4276+
cartPaymentMethodsTransformRun(
4277+
"""
4278+
The result of the Function.
4279+
"""
4280+
result: CartPaymentMethodsTransformRunResult!
4281+
): Void!
4282+
42234283
"""
42244284
Handles the Function result.
42254285
"""
@@ -4254,7 +4314,7 @@ input Operation @oneOf {
42544314
Use this operation when you want to conditionally hide payment methods based on
42554315
checkout attributes, customer data, or other business logic implemented in your Function.
42564316
"""
4257-
hide: HideOperation
4317+
paymentMethodHide: PaymentMethodHideOperation
42584318

42594319
"""
42604320
A request to move a payment method to a new position in the checkout display order.
@@ -4265,7 +4325,7 @@ input Operation @oneOf {
42654325
Use this operation when you want to prioritize certain payment methods based on
42664326
checkout context, customer preferences, or other business logic implemented in your Function.
42674327
"""
4268-
move: MoveOperation
4328+
paymentMethodMove: PaymentMethodMoveOperation
42694329

42704330
"""
42714331
A request to change the displayed name of a payment method during checkout.
@@ -4277,7 +4337,7 @@ input Operation @oneOf {
42774337
payment methods based on checkout details, locale, or other business logic
42784338
implemented in your Function.
42794339
"""
4280-
rename: RenameOperation
4340+
paymentMethodRename: PaymentMethodRenameOperation
42814341
}
42824342

42834343
"""
@@ -4343,6 +4403,70 @@ enum PaymentCustomizationPaymentMethodPlacement {
43434403
PAYMENT_METHOD
43444404
}
43454405

4406+
"""
4407+
A request to hide a payment method during checkout.
4408+
4409+
When your Function returns this operation, it removes the specified payment method
4410+
from the available options shown to customers during checkout.
4411+
4412+
Use this operation when you want to conditionally hide payment methods based on
4413+
checkout attributes, customer data, or other business logic implemented in your Function.
4414+
"""
4415+
input PaymentMethodHideOperation {
4416+
"""
4417+
The identifier of the payment method to hide out.
4418+
"""
4419+
paymentMethodId: ID!
4420+
4421+
"""
4422+
Placement types to hide. If not provided, all placements will be hidden.
4423+
"""
4424+
placements: [PaymentCustomizationPaymentMethodPlacement!]
4425+
}
4426+
4427+
"""
4428+
A request to move a payment method to a new position in the checkout display order.
4429+
4430+
When your Function returns this operation, it changes the display order of payment methods
4431+
by placing the specified payment method at the requested index position.
4432+
4433+
Use this operation when you want to prioritize certain payment methods based on
4434+
checkout context, customer preferences, or other business logic implemented in your Function.
4435+
"""
4436+
input PaymentMethodMoveOperation {
4437+
"""
4438+
The index to move the payment method to.
4439+
"""
4440+
index: Int!
4441+
4442+
"""
4443+
The identifier of the payment method to move.
4444+
"""
4445+
paymentMethodId: ID!
4446+
}
4447+
4448+
"""
4449+
A request to change the displayed name of a payment method during checkout.
4450+
4451+
When your Function returns this operation, it replaces the default name of the
4452+
specified payment method with the custom name that's provided in the request.
4453+
4454+
Use this operation when you want to provide more context or clarity about
4455+
payment methods based on checkout details, locale, or other business logic
4456+
implemented in your Function.
4457+
"""
4458+
input PaymentMethodRenameOperation {
4459+
"""
4460+
The new name for the payment method.
4461+
"""
4462+
name: String!
4463+
4464+
"""
4465+
The identifier of the payment method to rename.
4466+
"""
4467+
paymentMethodId: ID!
4468+
}
4469+
43464470
"""
43474471
The goods and services that merchants offer to customers. Products can include details such as
43484472
title, vendor, and custom data stored in [metafields](https://shopify.dev/docs/apps/build/custom-data).

checkout/javascript/payment-customization/default/shopify.extension.toml.liquid

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
api_version = "2025-01"
1+
api_version = "2025-07"
22

33
[[extensions]]
44
name = "t:name"
@@ -8,9 +8,9 @@ type = "function"
88
description = "t:description"
99

1010
[[extensions.targeting]]
11-
target = "purchase.payment-customization.run"
12-
input_query = "src/run.graphql"
13-
export = "run"
11+
target = "cart.payment-methods.transform.run"
12+
input_query = "src/cart_payment_methods_transform_run.graphql"
13+
export = "cart-payment-methods-transform-run"
1414

1515
[extensions.build]
1616
command = ""

checkout/javascript/payment-customization/default/src/run.graphql.liquid renamed to checkout/javascript/payment-customization/default/src/cart_payment_methods_transform_run.graphql.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query RunInput {
1+
query CartPaymentMethodsTransformRunInput {
22
paymentCustomization {
33
metafield(namespace: "$app:{{handle | replace: " ", "-" | downcase}}", key: "function-configuration") {
44
value
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
// @ts-check
3+
4+
/**
5+
* @typedef {import("../generated/api").CartPaymentMethodsTransformRunInput} CartPaymentMethodsTransformRunInput
6+
* @typedef {import("../generated/api").CartPaymentMethodsTransformRunResult} CartPaymentMethodsTransformRunResult
7+
*/
8+
9+
/**
10+
* @type {CartPaymentMethodsTransformRunResult}
11+
*/
12+
const NO_CHANGES = {
13+
operations: [],
14+
};
15+
16+
/**
17+
* @param {CartPaymentMethodsTransformRunInput} input
18+
* @returns {CartPaymentMethodsTransformRunResult}
19+
*/
20+
export function cartPaymentMethodsTransformRun(input) {
21+
const configuration = JSON.parse(
22+
input?.paymentCustomization?.metafield?.value ?? "{}"
23+
);
24+
25+
return NO_CHANGES;
26+
};
27+
{%- elsif flavor contains "typescript" -%}
28+
import type {
29+
CartPaymentMethodsTransformRunInput,
30+
CartPaymentMethodsTransformRunResult,
31+
} from "../generated/api";
32+
33+
const NO_CHANGES: CartPaymentMethodsTransformRunResult = {
34+
operations: [],
35+
};
36+
37+
type Configuration = {};
38+
39+
export function cartPaymentMethodsTransformRun(input: CartPaymentMethodsTransformRunInput): CartPaymentMethodsTransformRunResult {
40+
const configuration: Configuration = JSON.parse(
41+
input?.paymentCustomization?.metafield?.value ?? "{}"
42+
);
43+
return NO_CHANGES;
44+
};
45+
{%- endif -%}

checkout/javascript/payment-customization/default/src/run.test.liquid renamed to checkout/javascript/payment-customization/default/src/cart_payment_methods_transform_run.test.liquid

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{%- if flavor contains "vanilla-js" -%}
22
import { describe, it, expect } from 'vitest';
3-
import { run } from './run';
3+
import { cartPaymentMethodsTransformRun } from './cart_payment_methods_transform_run';
44

55
/**
6-
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
6+
* @typedef {import("../generated/api").CartPaymentMethodsTransformRunResult} CartPaymentMethodsTransformRunResult
77
*/
88

99
describe('payment customization function', () => {
1010
it('returns no operations without configuration', () => {
11-
const result = run({
11+
const result = cartPaymentMethodsTransformRun({
1212
paymentCustomization: {
1313
metafield: null
1414
}
1515
});
16-
const expected = /** @type {FunctionRunResult} */ ({ operations: [] });
16+
const expected = /** @type {CartPaymentMethodsTransformRunResult} */ ({ operations: [] });
1717

1818
expect(result).toEqual(expected);
1919
});
2020
});
2121
{%- elsif flavor contains "typescript" -%}
2222
import { describe, it, expect } from 'vitest';
23-
import { run } from './run';
24-
import { FunctionRunResult } from '../generated/api';
23+
import { cartPaymentMethodsTransformRun } from './cart_payment_methods_transform_run';
24+
import { CartPaymentMethodsTransformRunResult } from '../generated/api';
2525

2626
describe('payment customization function', () => {
2727
it('returns no operations without configuration', () => {
28-
const result = run({
28+
const result = cartPaymentMethodsTransformRun({
2929
paymentCustomization: {
3030
metafield: null
3131
}
3232
});
33-
const expected: FunctionRunResult = { operations: [] };
33+
const expected: CartPaymentMethodsTransformRunResult = { operations: [] };
3434

3535
expect(result).toEqual(expected);
3636
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './run';
1+
export * from './cart_payment_methods_transform_run';

checkout/javascript/payment-customization/default/src/run.liquid

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)