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

Conversation

Phatye
Copy link
Contributor

@Phatye Phatye commented Dec 5, 2024

WHY are these changes introduced?

Story https://github.com/Shopify/payments-platform/issues/7130
Figma docs
PR 3 of 5

We want to allow payment partners to indicate if they support Mail Order/Telephone Order (MOTO) payment in their credit card payment extension config so as to gate the ability of merchants to manually enter credit card details in draft orders or order edit flows.

WHAT is this pull request doing?

Introduces new configuration for payment app extensions called supports_moto which is a boolean value that indicates whether the payment app supports MOTO payments.

How to test your changes?

  • Checkout this branch
  • Use the commands from here to create app, generate extension, submit a dev build and create draft version.
  • Note the cli now requires supports_moto flag to create extension
  • PS: Login as Shopify Org. You'll also need to create an encryption certificate for the extension. Spin has Outbound email viewer to view the emails to approve certificate request. You can manually grant access scope to the certificate in partner_certificate_use_cases model in partners database.

Post-release steps

Documentation shipped in https://github.com/Shopify/shopify-dev/pull/51330

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Dec 5, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.22% (+0.09% 🔼)
8849/11764
🟡 Branches
70.48% (+0.17% 🔼)
4293/6091
🟡 Functions
75.15% (+0.08% 🔼)
2316/3082
🟡 Lines
75.77% (+0.08% 🔼)
8366/11041
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟡
... / dev.ts
77.78% (-0.22% 🔻)
65% (-0.22% 🔻)
81.25% (+3.47% 🔼)
74.36% (-0.64% 🔻)
🟢
... / app-event-watcher.ts
93.83% (-1.23% 🔻)
86.49% (-2.7% 🔻)
90.48% 98.61%
🔴
... / partners-client.ts
25.9% (-0.38% 🔻)
37.5% 17.86%
25.56% (-0.19% 🔻)
🔴
... / system.ts
46.67% (+1.99% 🔼)
31.25% (-0.33% 🔻)
66.67%
47.73% (+2.08% 🔼)

Test suite run success

1998 tests passing in 903 suites.

Report generated by 🧪jest coverage report action from cf2bc94

@Phatye Phatye marked this pull request as ready for review December 9, 2024 20:37
@Phatye Phatye requested a review from a team as a code owner December 9, 2024 20:37
Copy link
Contributor

github-actions bot commented Dec 9, 2024

We detected some changes at packages/*/src and there are no updates in the .changeset.
If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

@@ -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?

Copy link
Member

@weber-gregoire weber-gregoire left a comment

Choose a reason for hiding this comment

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

Changes look good from my perspective, but I'm not very familiar with the CLI code, it's not impossible that I've missed something.
I suggest you to wait to have another review from someone more familiar with it before shipping.

@buzuloiu buzuloiu force-pushed the add-support-moto branch 2 times, most recently from 91cd6e9 to 2269a79 Compare January 7, 2025 21:37
@buzuloiu buzuloiu requested a review from a team January 10, 2025 15:03
@buzuloiu buzuloiu added this pull request to the merge queue Jan 10, 2025
Merged via the queue into main with commit acbd399 Jan 10, 2025
27 checks passed
@buzuloiu buzuloiu deleted the add-support-moto branch January 10, 2025 15:47
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.

6 participants