Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MOTO in credit card payments extension schema #5043

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const config: CreditCardPaymentsAppExtensionConfigType = {
supported_countries: ['CA'],
supported_payment_methods: ['PAYMENT_METHOD'],
supported_buyer_contexts: [{currency: 'USD'}, {currency: 'CAD'}],
supports_moto: true,
supports_3ds: false,
test_mode_available: true,
supports_deferred_payments: false,
Expand Down Expand Up @@ -194,6 +195,7 @@ describe('creditCardPaymentsAppExtensionDeployConfig', () => {
supported_payment_methods: config.supported_payment_methods,
supported_buyer_contexts: config.supported_buyer_contexts,
test_mode_available: config.test_mode_available,
supports_moto: config.supports_moto,
supports_3ds: config.supports_3ds,
supports_deferred_payments: config.supports_deferred_payments,
supports_installments: config.supports_installments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const CreditCardPaymentsAppExtensionSchema = BasePaymentsAppExtensionSche
targeting: zod.array(zod.object({target: zod.literal(CREDIT_CARD_TARGET)})).length(1),
verification_session_url: zod.string().url().optional(),
ui_extension_handle: zod.string().optional(),
supports_moto: zod.boolean(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is not optional, it will break any existing extension that doesn't have it. Is this an accepted outcome? should it have a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the CLI will be used when partners want to update/create extensions. At this point we want them to supply a value. Default value will be used in core when existing extensions are loaded in Core (https://github.com/Shopify/shopify/pull/559538). Are there other scenarios where CLI is used to manage/load extensions that I am missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I say existing extensions, i mean at the moment of updating them via CLI, it will fail until they provide this value.

Simple case:

  • You have an automated deploy in CI, if we release this, that deploy will start failing until you provide this value.

Is this the expected behaviour? If it is, then OK; just wanted to confirm!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think it's worth it to provide default values similar to what is done in core

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we had some team discussion and decided it might be better to fail deploys on releasing this to force the new param instead of offering a default. I added some better error messaging in cf2bc94, and the unit tests I wrote for it work, but I'm having trouble tophatting this.

When I run pnpm shopify app dev for my extension in spin, I get

╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  App configuration is not valid                                              │
│  Validation errors in ../cli-apps/empowered-marketplace-app/extensions/cred  │
│  it-card/shopify.extension.toml:                                             │
│                                                                              │
│  • []: Invalid input                                                         │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

instead of the error message I defined for either the wrong type or the value being missing altogether.

@isaacroldan is this the right kind of validation to introduce here? Is there a better way to define this? I'm not sure I have enough cli context to understand why this isn't working.

Copy link
Contributor

@buzuloiu buzuloiu Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think this has something to do with how we're defining/loading the schema for this?

export const CreditCardPaymentsAppExtensionSchema = BasePaymentsAppExtensionSchema.merge(DeferredPaymentsSchema)
.merge(ConfirmationSchema)
.merge(MultipleCaptureSchema)
.merge(SupportedBuyerContextsSchema)
.required({
refund_session_url: true,
capture_session_url: true,
void_session_url: true,
})
.extend({

I added some debug code to the loader here

      parsed.errors.forEach((error) => console.log(error))
output of `pnpm shopify app dev --path=../cli-apps/test`
{
  code: 'invalid_union',
  unionErrors: [
    ZodError: [
      {
        "received": "payments.credit-card.render",
        "code": "invalid_literal",
        "expected": "payments.offsite.render",
        "path": [
          "targeting",
          0,
          "target"
        ],
        "message": "Invalid literal value, expected \"payments.offsite.render\""
      }
    ]
        at file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:56
        at Array.map (<anonymous>)
        at ZodUnion._parse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:40)
        at ZodUnion._parseSync (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:624:29)
        at ZodUnion.safeParse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:654:29)
        at Object.parseConfigurationObject (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/extensions/specification.js:61:47)
        at parseConfigurationObjectAgainstSpecification (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:90:25)
        at AppLoader.createExtensionInstance (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:284:31)
        at file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:355:33
        at Array.map (<anonymous>) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    },
    ZodError: [
      {
        "received": "payments.credit-card.render",
        "code": "invalid_literal",
        "expected": "payments.redeemable.render",
        "path": [
          "targeting",
          0,
          "target"
        ],
        "message": "Invalid literal value, expected \"payments.redeemable.render\""
      },
      {
        "code": "invalid_type",
        "expected": "string",
        "received": "undefined",
        "path": [
          "balance_url"
        ],
        "message": "Required"
      }
    ]
        at file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:56
        at Array.map (<anonymous>)
        at ZodUnion._parse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:40)
        at ZodUnion._parseSync (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:624:29)
        at ZodUnion.safeParse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:654:29)
        at Object.parseConfigurationObject (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/extensions/specification.js:61:47)
        at parseConfigurationObjectAgainstSpecification (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:90:25)
        at AppLoader.createExtensionInstance (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:284:31)
        at file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:355:33
        at Array.map (<anonymous>) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    },
    ZodError: [
      {
        "received": "payments.credit-card.render",
        "code": "invalid_literal",
        "expected": "payments.custom-onsite.render",
        "path": [
          "targeting",
          0,
          "target"
        ],
        "message": "Invalid literal value, expected \"payments.custom-onsite.render\""
      }
    ]
        at file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:56
        at Array.map (<anonymous>)
        at ZodUnion._parse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:40)
        at ZodUnion._parseSync (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:624:29)
        at ZodUnion.safeParse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:654:29)
        at Object.parseConfigurationObject (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/extensions/specification.js:61:47)
        at parseConfigurationObjectAgainstSpecification (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:90:25)
        at AppLoader.createExtensionInstance (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:284:31)
        at file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:355:33
        at Array.map (<anonymous>) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    },
    ZodError: [
      {
        "received": "payments.credit-card.render",
        "code": "invalid_literal",
        "expected": "payments.custom-credit-card.render",
        "path": [
          "targeting",
          0,
          "target"
        ],
        "message": "Invalid literal value, expected \"payments.custom-credit-card.render\""
      }
    ]
        at file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:56
        at Array.map (<anonymous>)
        at ZodUnion._parse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:40)
        at ZodUnion._parseSync (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:624:29)
        at ZodUnion.safeParse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:654:29)
        at Object.parseConfigurationObject (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/extensions/specification.js:61:47)
        at parseConfigurationObjectAgainstSpecification (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:90:25)
        at AppLoader.createExtensionInstance (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:284:31)
        at file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:355:33
        at Array.map (<anonymous>) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    },
    ZodError: [
      {
        "code": "invalid_type",
        "expected": "boolean",
        "received": "string",
        "path": [
          "supports_moto"
        ],
        "message": "Value must be Boolean"
      }
    ]
        at file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:56
        at Array.map (<anonymous>)
        at ZodUnion._parse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:2589:40)
        at ZodUnion._parseSync (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:624:29)
        at ZodUnion.safeParse (file:///home/spin/src/github.com/Shopify/cli/node_modules/.pnpm/zod@3.22.3/node_modules/zod/lib/index.mjs:654:29)
        at Object.parseConfigurationObject (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/extensions/specification.js:61:47)
        at parseConfigurationObjectAgainstSpecification (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:90:25)
        at AppLoader.createExtensionInstance (file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:284:31)
        at file:///home/spin/src/github.com/Shopify/cli/packages/app/dist/cli/models/app/loader.js:355:33
        at Array.map (<anonymous>) {
      issues: [Array],
      addIssue: [Function (anonymous)],
      addIssues: [Function (anonymous)],
      errors: [Array]
    }
  ],
  path: [],
  message: 'Invalid input'
}
╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  App configuration is not valid                                              │
│  Validation errors in                                                        │
│  ../cli-apps/test/extensions/credit-card/shopify.extension.toml:             │
│                                                                              │
│  • []: Invalid input                                                         │
│                                                                              │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

I'm not too familiar with Zod, but is what's happening here that it's not managing to resolve it to a credit card payment extension? Which is why the error is there and the specific schema tests pass, but then when we try to do it all together it fails?

encryption_certificate_fingerprint: zod
.string()
.min(1, {message: "Encryption certificate fingerprint can't be blank"}),
Expand Down Expand Up @@ -72,6 +73,7 @@ export interface CreditCardPaymentsAppExtensionDeployConfigType extends BasePaym
supports_3ds: boolean

// CreditCard-specific fields
supports_moto: boolean
start_verification_session_url?: string
ui_extension_registration_uuid?: string
ui_extension_handle?: string
Expand Down Expand Up @@ -106,6 +108,7 @@ export function creditCardDeployConfigToCLIConfig(
supported_buyer_contexts: config.supported_buyer_contexts,
test_mode_available: config.test_mode_available,
supports_3ds: config.supports_3ds,
supports_moto: config.supports_moto,
supports_deferred_payments: config.supports_deferred_payments,
supports_installments: config.supports_installments,
verification_session_url: config.start_verification_session_url,
Expand All @@ -132,6 +135,7 @@ export async function creditCardPaymentsAppExtensionDeployConfig(
supported_buyer_contexts: config.supported_buyer_contexts,
test_mode_available: config.test_mode_available,
supports_3ds: config.supports_3ds,
supports_moto: config.supports_moto,
supports_deferred_payments: config.supports_deferred_payments,
encryption_certificate_fingerprint: config.encryption_certificate_fingerprint,
supports_installments: config.supports_installments,
Expand Down
Loading