Skip to content

Conversation

tiagocandido
Copy link
Contributor

@tiagocandido tiagocandido commented Jun 13, 2025

What changes are you making?

This PR adds embedded checkout support using Schema 2025-04 specification. The implementation includes:

  • Data Models: Added CheckoutStatePayload, CheckoutCompletePayload, WebPixelsPayload, and ErrorPayload types for embedded checkout events. Added CheckoutOptions and AppAuthentication for partner authentication configuration.

  • CheckoutBridge: Extended with embedParams() method to generate authentication tokens and configuration parameters for embedded checkout URLs.

  • CheckoutWebView: Enhanced message handling to process both legacy and embedded checkout events. Added URL building logic to include embed parameters when CheckoutOptions is provided.

  • CheckoutWebViewController: Added options parameter to initializer and implemented embedded checkout delegate methods with error recovery logic.

  • CheckoutDelegate: Extended protocol with embedded checkout event methods (checkoutDidChangeState, checkoutDidComplete, checkoutDidFail, checkoutDidEmitWebPixelEvent) with default no-op implementations for backward compatibility.

  • Test Infrastructure: Updated mocks and test helpers to support embedded checkout functionality.

All changes maintain backward compatibility - existing checkout flows continue to work unchanged.

How to test

  1. Legacy Checkout Flow: Verify existing checkout implementations continue to work without modifications
  2. Embedded Checkout Flow:
    let options = CheckoutOptions(appAuthentication: .token("your-token"))
    let controller = CheckoutWebViewController(checkoutURL: url, delegate: self, options: options)
  3. Event Handling: Implement embedded checkout delegate methods to receive state changes, completion events, and errors
  4. URL Parameters: Verify embed parameters are correctly added to checkout URLs when options are provided
  5. Error Recovery: Test error handling and recovery flows for embedded checkout scenarios

Before you merge

[!IMPORTANT]


[!TIP]
See the https://github.com/shopify/checkout-sheet-kit-swift/blob/main/.github/CONTRIBUTING.md#releasing-a-new-version for instructions on how to publish a new version of the library.

@tiagocandido tiagocandido requested a review from a team as a code owner June 13, 2025 17:04
@tiagocandido tiagocandido force-pushed the ts/partner-authentication branch from 7dfe1b3 to 27ca4c8 Compare June 25, 2025 15:57
@tiagocandido tiagocandido changed the title Initial draft of partner authentication Partner App authentication support Jun 25, 2025
@tiagocandido tiagocandido force-pushed the ts/partner-authentication branch 5 times, most recently from 116945a to f131897 Compare June 25, 2025 18:11
@tiagocandido tiagocandido changed the title Partner App authentication support Add support to Partner App authentication Jun 25, 2025
@tiagocandido tiagocandido force-pushed the ts/partner-authentication branch 2 times, most recently from f56a6ea to 20b8c8e Compare July 11, 2025 20:35
@tiagocandido tiagocandido changed the title Add support to Partner App authentication (WIP) Migration to CheckoutKit 4.0 Jul 11, 2025
This commit introduces the complete data model infrastructure for embedded
checkout functionality using the Schema 2025-04 specification.

Key additions:
- CheckoutStatePayload, CheckoutCompletePayload, WebPixelsPayload for event handling
- Complete embedded checkout data types with 'Embedded' prefixes to avoid naming conflicts
- CheckoutOptions and AppAuthentication for configuration
- AnyCodable helper for handling arbitrary JSON payloads
- Error payload models for embedded checkout error handling

All types are prefixed with 'Embedded' to avoid conflicts with existing
types in the codebase. This maintains backward compatibility while
enabling new embedded checkout functionality.
This commit extends the CheckoutBridge with embedded checkout functionality
while maintaining backward compatibility with existing checkout flows.

Key additions:
- embedParams() method to generate authentication and configuration parameters
- Support for embedded checkout authentication tokens
- Protocol version 2025-04 for embedded checkout specification
- Color scheme and platform parameter generation

The existing CheckoutBridge enum interface is preserved, with new
functionality added as static methods. This ensures no breaking
changes to current integrations.
This commit extends CheckoutWebView with comprehensive embedded checkout
functionality while maintaining backward compatibility.

Key additions:
- Extended CheckoutWebViewDelegate with embedded checkout event methods
- checkoutOptions property to configure embedded checkout authentication
- buildCheckoutURL() method to add embed query parameters with authentication tokens
- Enhanced message handler supporting both legacy and embedded checkout events
- Comprehensive event decoders for embedded checkout payloads:
  - CheckoutStatePayload for state change events
  - CheckoutCompletePayload for completion events
  - ErrorPayload array for error handling
  - WebPixelsPayload for web pixel events

The implementation prioritizes embedded checkout event handling while
gracefully falling back to legacy CheckoutBridge decoding for existing
checkout flows. This ensures full backward compatibility.
…utDelegate

This commit integrates embedded checkout functionality into the view controller
layer and delegate protocol while maintaining backward compatibility.

CheckoutWebViewController changes:
- Added CheckoutOptions parameter to initializer for embedded checkout configuration
- Implemented embedded checkout delegate methods:
  - checkoutViewDidChangeState() for state change events
  - checkoutViewDidComplete() for completion with embedded payload
  - checkoutViewDidFail() for error handling with embedded error payloads
  - checkoutViewDidEmitWebPixelEvent() for embedded web pixel events
- Enhanced error recovery logic for embedded checkout error types

CheckoutDelegate changes:
- Extended protocol with embedded checkout event methods
- Added default implementations for all new methods to maintain compatibility
- Documented embedded checkout methods with Schema 2025-04 specification

All changes are backward compatible - existing implementations continue
to work unchanged while new embedded checkout functionality is available
for apps that need it.
This commit updates the test infrastructure to support the new embedded
checkout interfaces while maintaining compatibility with existing tests.

CheckoutViewControllerTests changes:
- Updated MockCheckoutWebViewController initializations to include new parameters
- Added createEmptyCheckoutCompletedPayload() helper for embedded checkout tests
- Maintained backward compatibility with existing test methods

MockCheckoutWebViewDelegate changes:
- Added embedded checkout delegate method implementations
- Added properties to capture embedded checkout event payloads
- Added XCTestExpectation properties for embedded checkout event testing
- Maintained all existing legacy delegate method functionality

All existing tests continue to pass while new embedded checkout
functionality can be tested using the extended mock interfaces.
@tiagocandido tiagocandido force-pushed the ts/partner-authentication branch from bc2e2b0 to 7d9c9f6 Compare July 29, 2025 06:54
@tiagocandido tiagocandido marked this pull request as draft July 29, 2025 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant