Skip to content

Commit 5ad8ca7

Browse files
feat: support new Cart respondWith instead of CartInput (#409)
* feat: support new Cart respondWith instead of CartInput * fix: swift test compilation
1 parent 0658003 commit 5ad8ca7

File tree

9 files changed

+172
-272
lines changed

9 files changed

+172
-272
lines changed

modules/@shopify/checkout-sheet-kit/ios/ShopifyCheckoutSheetKit+EventSerialization.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,6 @@ internal enum ShopifyEventSerialization {
4646
return [:]
4747
}
4848

49-
/**
50-
* Converts a JSON string to a dictionary.
51-
*/
52-
static func stringToJSON(from value: String?) -> [String: Any]? {
53-
guard let data = value?.data(using: .utf8, allowLossyConversion: false) else { return [:] }
54-
do {
55-
return try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]
56-
} catch {
57-
print("Failed to convert string to JSON: \(error)", value ?? "nil")
58-
return [:]
59-
}
60-
}
61-
6249
/**
6350
* Converts a CheckoutCompleteEvent to a React Native compatible dictionary.
6451
*/

modules/@shopify/checkout-sheet-kit/src/events.d.ts

Lines changed: 66 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -242,36 +242,85 @@ export interface MailingAddress {
242242
*/
243243
export interface CartDelivery {
244244
/** List of selectable delivery addresses */
245-
addresses: CartDeliveryAddress[];
245+
addresses: CartSelectableAddress[];
246246
}
247247

248248
/**
249-
* A delivery address with selection state.
249+
* A selectable delivery address with selection and reuse settings.
250250
*/
251-
export interface CartDeliveryAddress {
251+
export interface CartSelectableAddress {
252252
/** The mailing address details */
253253
address: MailingAddress;
254254
/** Whether this address is currently selected for delivery */
255255
selected?: boolean;
256+
/** Whether this address should only be used for this checkout */
257+
oneTimeUse?: boolean;
256258
}
257259

258260
/**
259261
* A delivery address of the buyer that is interacting with the cart.
260262
* This is a union type to support future address types.
261-
* Currently only CartDeliveryAddress is supported.
263+
* Currently only CartSelectableAddress is supported.
262264
*
263265
* @see https://shopify.dev/docs/api/storefront/latest/unions/CartAddress
264266
*/
265-
export type CartAddress = CartDeliveryAddress;
267+
export type CartAddress = CartSelectableAddress;
268+
269+
/**
270+
* Remote token payment credential for delegated payment processing.
271+
*/
272+
export interface RemoteTokenPaymentCredential {
273+
/** The payment token */
274+
token: string;
275+
/** The type of token (e.g., "card") */
276+
tokenType: string;
277+
/** The token handler (e.g., "delegated") */
278+
tokenHandler: string;
279+
}
280+
281+
/**
282+
* Cart credential containing payment authentication data.
283+
*/
284+
export interface CartCredential {
285+
/** Remote token payment credential for tokenized payments */
286+
remoteTokenPaymentCredential?: RemoteTokenPaymentCredential;
287+
}
266288

267289
/**
268290
* Payment instrument available for selection at checkout.
269-
* Output type from Storefront API.
291+
* Represents a credit card or other payment method with its details.
270292
*
271293
* @see https://shopify.dev/docs/api/storefront/latest/objects/CartPaymentInstrument
272294
*/
273295
export interface CartPaymentInstrument {
274-
externalReference: string;
296+
/** Type discriminator for the payment instrument */
297+
__typename?: string;
298+
/** Unique identifier for this payment instrument */
299+
externalReferenceId: string;
300+
/** Payment credentials for this instrument */
301+
credentials?: CartCredential[];
302+
/** Name of the cardholder */
303+
cardHolderName?: string;
304+
/** Last digits of the card number */
305+
lastDigits?: string;
306+
/** Expiry month (1-12) */
307+
month?: number;
308+
/** Expiry year (4-digit) */
309+
year?: number;
310+
/** Card brand (e.g., VISA, MASTERCARD) */
311+
brand?: CardBrand;
312+
/** Billing address for the payment instrument */
313+
billingAddress?: MailingAddress;
314+
}
315+
316+
/**
317+
* A payment method containing payment instruments.
318+
*/
319+
export interface CartPaymentMethod {
320+
/** Type discriminator (e.g., "CreditCardPaymentMethod") */
321+
__typename?: string;
322+
/** Payment instruments for this method */
323+
instruments: CartPaymentInstrument[];
275324
}
276325

277326
/**
@@ -280,7 +329,8 @@ export interface CartPaymentInstrument {
280329
* @see https://shopify.dev/docs/api/storefront/latest/objects/CartPayment
281330
*/
282331
export interface CartPayment {
283-
instruments: CartPaymentInstrument[];
332+
/** Payment methods available for the cart */
333+
methods: CartPaymentMethod[];
284334
}
285335

286336
/**
@@ -408,108 +458,6 @@ export interface CheckoutResponseError {
408458
fieldTarget?: string;
409459
}
410460

411-
/**
412-
* Mailing address input for delivery.
413-
*
414-
* @see https://shopify.dev/docs/api/storefront/latest/input-objects/MailingAddressInput
415-
*/
416-
export interface MailingAddressInput {
417-
/** First line of the address (street address or PO Box) */
418-
address1?: string;
419-
/** Second line of the address (apartment, suite, unit) */
420-
address2?: string;
421-
/** City, district, village, or town */
422-
city?: string;
423-
/** Company or organization name */
424-
company?: string;
425-
/**
426-
* Two-letter country code - REQUIRED
427-
* Must be exactly 2 characters (ISO 3166-1 alpha-2 format)
428-
* Examples: "US", "CA", "GB", "AU"
429-
*/
430-
countryCode: string;
431-
/** First name of the customer */
432-
firstName?: string;
433-
/** Last name of the customer */
434-
lastName?: string;
435-
/** Phone number (E.164 format recommended, e.g., +16135551111) */
436-
phone?: string;
437-
/** Province/state code (e.g., "CA", "ON") */
438-
provinceCode?: string;
439-
/** Zip or postal code */
440-
zip?: string;
441-
}
442-
443-
/**
444-
* Delivery address with selection state.
445-
* Used within CartDeliveryInput.
446-
*/
447-
export interface CartDeliveryAddressInput {
448-
/**
449-
* The delivery address details.
450-
*/
451-
address: MailingAddressInput;
452-
/**
453-
* Whether this address is selected as the active delivery address.
454-
* Optional - use to pre-select an address from multiple options.
455-
*/
456-
selected?: boolean;
457-
}
458-
459-
/**
460-
* Delivery-related fields for the cart.
461-
*
462-
* @see https://shopify.dev/docs/api/storefront/latest/input-objects/CartDeliveryInput
463-
*/
464-
export interface CartDeliveryInput {
465-
/**
466-
* Array of selectable addresses presented to the buyer.
467-
*/
468-
addresses?: CartDeliveryAddressInput[];
469-
}
470-
471-
/**
472-
* The customer associated with the cart.
473-
*
474-
* @see https://shopify.dev/docs/api/storefront/latest/input-objects/CartBuyerIdentityInput
475-
*/
476-
export interface CartBuyerIdentityInput {
477-
/** Email address of the buyer */
478-
email?: string;
479-
/** Phone number of the buyer */
480-
phone?: string;
481-
/** Two-letter country code for the buyer's location */
482-
countryCode?: string;
483-
}
484-
485-
/**
486-
* Cart input for updating cart state via checkout events.
487-
* Mirrors the Storefront API CartInput structure.
488-
*
489-
* @see https://shopify.dev/docs/api/storefront/latest/input-objects/CartInput
490-
*/
491-
export interface CartInput {
492-
/**
493-
* Delivery-related fields for the cart.
494-
*/
495-
delivery?: CartDeliveryInput;
496-
/**
497-
* The customer associated with the cart.
498-
* Optional - use to update buyer identity information.
499-
*/
500-
buyerIdentity?: CartBuyerIdentityInput;
501-
/**
502-
* Case-insensitive discount codes.
503-
* Optional - use to apply discount codes to the cart.
504-
*/
505-
discountCodes?: string[];
506-
/**
507-
* Payment instruments for the cart.
508-
* Optional - use to update payment methods.
509-
*/
510-
paymentInstruments?: CartPaymentInstrumentInput[];
511-
}
512-
513461
/**
514462
* Event emitted when checkout starts an address change flow.
515463
*
@@ -551,9 +499,9 @@ export interface CheckoutAddressChangeStartEvent {
551499
*/
552500
export interface CheckoutAddressChangeStartResponsePayload {
553501
/**
554-
* Updated cart input with the delivery addresses to set.
502+
* Updated cart with the delivery addresses to set.
555503
*/
556-
cart?: CartInput;
504+
cart?: Cart;
557505
/**
558506
* Optional array of errors if the address selection failed.
559507
*/
@@ -574,45 +522,6 @@ export type CardBrand =
574522
| 'MAESTRO'
575523
| 'UNKNOWN';
576524

577-
/**
578-
* Expiry date for a payment instrument.
579-
*/
580-
export interface ExpiryInput {
581-
/** Month (1-12) */
582-
month: number;
583-
/** Four-digit year */
584-
year: number;
585-
}
586-
587-
/**
588-
* Display fields for a payment instrument shown to the buyer.
589-
*/
590-
export interface CartPaymentInstrumentDisplayInput {
591-
/** Last 4 digits of the card number */
592-
last4: string;
593-
/** Card brand (e.g., VISA, MASTERCARD) */
594-
brand: CardBrand;
595-
/** Name of the cardholder */
596-
cardHolderName: string;
597-
/** Card expiry date */
598-
expiry: ExpiryInput;
599-
}
600-
601-
/**
602-
* Input type for creating/updating payment instruments, aligned with Storefront API.
603-
* Display fields are grouped separately from the billing address.
604-
*
605-
* @see https://shopify.dev/docs/api/storefront/latest/input-objects/CartPaymentInstrumentInput
606-
*/
607-
export interface CartPaymentInstrumentInput {
608-
/** Unique identifier for this payment instrument */
609-
externalReference: string;
610-
/** Display information for the payment instrument */
611-
display: CartPaymentInstrumentDisplayInput;
612-
/** Billing address for the payment instrument */
613-
billingAddress: MailingAddressInput;
614-
}
615-
616525
/**
617526
* Event emitted when the buyer intends to change their payment method.
618527
*/
@@ -631,9 +540,9 @@ export interface CheckoutPaymentMethodChangeStartEvent {
631540
*/
632541
export interface CheckoutPaymentMethodChangeStartResponsePayload {
633542
/**
634-
* Updated cart input with the payment instruments to set.
543+
* Updated cart with the payment methods to set.
635544
*/
636-
cart?: CartInput;
545+
cart?: Cart;
637546
/**
638547
* Optional array of errors if the payment method selection failed.
639548
*/
@@ -669,31 +578,20 @@ export interface CheckoutSubmitStartEvent {
669578
sessionId: string;
670579
}
671580

672-
/**
673-
* Payment token input for delegated payment processing.
674-
*/
675-
export interface PaymentTokenInput {
676-
token: string;
677-
tokenType: string;
678-
tokenProvider: string;
679-
}
680-
681581
/**
682582
* Response payload for CheckoutSubmitStartEvent event.
683583
* Use with ShopifyCheckoutEventProvider.respondToEvent() or useShopifyEvent().respondWith()
684584
*
585+
* Payment credentials should be provided via cart.payment.methods[].instruments[].credentials
586+
*
685587
* Note: This response is only used when native payment delegation is enabled
686588
* for the authenticated app.
687589
*/
688590
export interface CheckoutSubmitStartResponsePayload {
689591
/**
690-
* Optional payment token information for delegated payment processing.
691-
*/
692-
payment?: PaymentTokenInput;
693-
/**
694-
* Updated cart input with delivery addresses and optional buyer identity.
592+
* Updated cart with payment credentials.
695593
*/
696-
cart?: CartInput;
594+
cart?: Cart;
697595
/**
698596
* Optional array of errors if the submission failed.
699597
*/

modules/@shopify/checkout-sheet-kit/src/index.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -501,27 +501,22 @@ export type {
501501
export type {
502502
Cart,
503503
CartAddress,
504-
CartBuyerIdentityInput,
505-
CartDeliveryAddressInput,
506-
CartDeliveryInput,
507-
CartInput,
508-
CardBrand,
504+
CartCredential,
509505
CartPayment,
510506
CartPaymentInstrument,
511-
CartPaymentInstrumentDisplayInput,
512-
CartPaymentInstrumentInput,
513-
PaymentTokenInput,
507+
CartPaymentMethod,
508+
CartSelectableAddress,
509+
CardBrand,
514510
CheckoutAddressChangeStartEvent,
515511
CheckoutAddressChangeStartResponsePayload,
516512
CheckoutCompleteEvent,
517-
CheckoutPaymentMethodChangeStartEvent ,
513+
CheckoutPaymentMethodChangeStartEvent,
518514
CheckoutPaymentMethodChangeStartResponsePayload,
519515
CheckoutResponseError,
520-
ExpiryInput,
521516
CheckoutStartEvent,
522517
CheckoutSubmitStartEvent,
523518
CheckoutSubmitStartResponsePayload,
524-
MailingAddressInput,
519+
RemoteTokenPaymentCredential,
525520
} from './events.d';
526521

527522
// Component types

modules/@shopify/checkout-sheet-kit/tests/testFixtures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function createTestCart(overrides?: Partial<Cart>): Cart {
7070
],
7171
},
7272
payment: {
73-
instruments: [],
73+
methods: [],
7474
},
7575
...overrides,
7676
};

0 commit comments

Comments
 (0)