Skip to content

Commit efb3697

Browse files
ginmrttjoyal
authored andcommitted
Update Payment Customization function templates
1 parent 0a043da commit efb3697

15 files changed

+468
-96
lines changed

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

Lines changed: 131 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ type CartLineCost {
335335
totalAmount: MoneyV2!
336336
}
337337

338+
"""
339+
The `CartPaymentMethodsTransformRunResult` object is the output of the Function
340+
run target. The object contains the operations to apply to payment methods in checkout.
341+
"""
342+
input CartPaymentMethodsTransformRunResult {
343+
"""
344+
The ordered list of operations to apply to the list of payment methods.
345+
"""
346+
operations: [Operation!]!
347+
}
348+
338349
"""
339350
Whether the product is in the specified collection.
340351
@@ -2791,6 +2802,45 @@ enum DeliveryMethod {
27912802
SHIPPING
27922803
}
27932804

2805+
"""
2806+
An operation to apply to the list of payment methods.
2807+
"""
2808+
input DeprecatedOperation @oneOf {
2809+
"""
2810+
A request to hide a payment method during checkout.
2811+
2812+
When your Function returns this operation, it removes the specified payment method
2813+
from the available options shown to customers during checkout.
2814+
2815+
Use this operation when you want to conditionally hide payment methods based on
2816+
checkout attributes, customer data, or other business logic implemented in your Function.
2817+
"""
2818+
hide: HideOperation @deprecated(reason: "Use `paymentMethodHide` instead.")
2819+
2820+
"""
2821+
A request to move a payment method to a new position in the checkout display order.
2822+
2823+
When your Function returns this operation, it changes the display order of payment methods
2824+
by placing the specified payment method at the requested index position.
2825+
2826+
Use this operation when you want to prioritize certain payment methods based on
2827+
checkout context, customer preferences, or other business logic implemented in your Function.
2828+
"""
2829+
move: MoveOperation @deprecated(reason: "Use `paymentMethodMove` instead.")
2830+
2831+
"""
2832+
A request to change the displayed name of a payment method during checkout.
2833+
2834+
When your Function returns this operation, it replaces the default name of the
2835+
specified payment method with the custom name that's provided in the request.
2836+
2837+
Use this operation when you want to provide more context or clarity about
2838+
payment methods based on checkout details, locale, or other business logic
2839+
implemented in your Function.
2840+
"""
2841+
rename: RenameOperation @deprecated(reason: "Use `paymentMethodRename` instead.")
2842+
}
2843+
27942844
"""
27952845
The output of the Function run target. The object contains the operations to
27962846
apply to payment methods in checkout. In API versions 2023-10 and beyond, this
@@ -2800,7 +2850,7 @@ input FunctionResult {
28002850
"""
28012851
The ordered list of operations to apply to the list of payment methods.
28022852
"""
2803-
operations: [Operation!]!
2853+
operations: [DeprecatedOperation!]!
28042854
}
28052855

28062856
"""
@@ -2810,7 +2860,7 @@ input FunctionRunResult {
28102860
"""
28112861
The ordered list of operations to apply to the list of payment methods.
28122862
"""
2813-
operations: [Operation!]!
2863+
operations: [DeprecatedOperation!]!
28142864
}
28152865

28162866
"""
@@ -3785,7 +3835,7 @@ type Localization {
37853835
"""
37863836
The market of the active localized experience.
37873837
"""
3788-
market: Market!
3838+
market: Market! @deprecated(reason: "This `market` field will be removed in a future version of the API.")
37893839
}
37903840

37913841
"""
@@ -4053,7 +4103,7 @@ type MailingAddress {
40534103
"""
40544104
The market of the address.
40554105
"""
4056-
market: Market
4106+
market: Market @deprecated(reason: "This `market` field will be removed in a future version of the API.")
40574107

40584108
"""
40594109
The full name of the customer, based on firstName and lastName.
@@ -4233,6 +4283,16 @@ input MoveOperation {
42334283
The root mutation for the API.
42344284
"""
42354285
type MutationRoot {
4286+
"""
4287+
Handles the Function result for the cart.payment-methods.transform.run target.
4288+
"""
4289+
cartPaymentMethodsTransformRun(
4290+
"""
4291+
The result of the Function.
4292+
"""
4293+
result: CartPaymentMethodsTransformRunResult!
4294+
): Void!
4295+
42364296
"""
42374297
Handles the Function result.
42384298
"""
@@ -4267,7 +4327,7 @@ input Operation @oneOf {
42674327
Use this operation when you want to conditionally hide payment methods based on
42684328
checkout attributes, customer data, or other business logic implemented in your Function.
42694329
"""
4270-
hide: HideOperation
4330+
paymentMethodHide: PaymentMethodHideOperation
42714331

42724332
"""
42734333
A request to move a payment method to a new position in the checkout display order.
@@ -4278,7 +4338,7 @@ input Operation @oneOf {
42784338
Use this operation when you want to prioritize certain payment methods based on
42794339
checkout context, customer preferences, or other business logic implemented in your Function.
42804340
"""
4281-
move: MoveOperation
4341+
paymentMethodMove: PaymentMethodMoveOperation
42824342

42834343
"""
42844344
A request to change the displayed name of a payment method during checkout.
@@ -4290,7 +4350,7 @@ input Operation @oneOf {
42904350
payment methods based on checkout details, locale, or other business logic
42914351
implemented in your Function.
42924352
"""
4293-
rename: RenameOperation
4353+
paymentMethodRename: PaymentMethodRenameOperation
42944354
}
42954355

42964356
"""
@@ -4356,6 +4416,70 @@ enum PaymentCustomizationPaymentMethodPlacement {
43564416
PAYMENT_METHOD
43574417
}
43584418

4419+
"""
4420+
A request to hide a payment method during checkout.
4421+
4422+
When your Function returns this operation, it removes the specified payment method
4423+
from the available options shown to customers during checkout.
4424+
4425+
Use this operation when you want to conditionally hide payment methods based on
4426+
checkout attributes, customer data, or other business logic implemented in your Function.
4427+
"""
4428+
input PaymentMethodHideOperation {
4429+
"""
4430+
The identifier of the payment method to hide out.
4431+
"""
4432+
paymentMethodId: ID!
4433+
4434+
"""
4435+
Placement types to hide. If not provided, all placements will be hidden.
4436+
"""
4437+
placements: [PaymentCustomizationPaymentMethodPlacement!]
4438+
}
4439+
4440+
"""
4441+
A request to move a payment method to a new position in the checkout display order.
4442+
4443+
When your Function returns this operation, it changes the display order of payment methods
4444+
by placing the specified payment method at the requested index position.
4445+
4446+
Use this operation when you want to prioritize certain payment methods based on
4447+
checkout context, customer preferences, or other business logic implemented in your Function.
4448+
"""
4449+
input PaymentMethodMoveOperation {
4450+
"""
4451+
The index to move the payment method to.
4452+
"""
4453+
index: Int!
4454+
4455+
"""
4456+
The identifier of the payment method to move.
4457+
"""
4458+
paymentMethodId: ID!
4459+
}
4460+
4461+
"""
4462+
A request to change the displayed name of a payment method during checkout.
4463+
4464+
When your Function returns this operation, it replaces the default name of the
4465+
specified payment method with the custom name that's provided in the request.
4466+
4467+
Use this operation when you want to provide more context or clarity about
4468+
payment methods based on checkout details, locale, or other business logic
4469+
implemented in your Function.
4470+
"""
4471+
input PaymentMethodRenameOperation {
4472+
"""
4473+
The new name for the payment method.
4474+
"""
4475+
name: String!
4476+
4477+
"""
4478+
The identifier of the payment method to rename.
4479+
"""
4480+
paymentMethodId: ID!
4481+
}
4482+
43594483
"""
43604484
The goods and services that merchants offer to customers. Products can include details such as
43614485
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)