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

Using a fixed_amount in Checkout for shipping causes version error #1485

Open
airjoshb opened this issue Nov 8, 2024 · 5 comments
Open

Using a fixed_amount in Checkout for shipping causes version error #1485

airjoshb opened this issue Nov 8, 2024 · 5 comments
Assignees
Labels

Comments

@airjoshb
Copy link

airjoshb commented Nov 8, 2024

Describe the bug

When describing shipping_options in a Stripe::Checkout::Session.create call in Checkout, using "type: 'fixed_amount'" triggers the following error,

Received unknown parameter: v1

When looking through the code, I found the issue in testing, which looks like it is appending "v1" to the url

To Reproduce

Add a "fixed_amount" type to shipping_rate_data in a create Checkout session call

Expected behavior

We should get the fixed amount information as an option.

Code snippets

should "Test shipping rates post" do
      Stripe::ShippingRate.create({
        display_name: "Sample Shipper",
        fixed_amount: {
          currency: "usd",
          amount: 400,
        },
        type: "fixed_amount",
      })
      assert_requested :post, "#{Stripe.api_base}/v1/shipping_rates"

Update 3:50pm PST: It appears that this error is triggered when more than one shipping_rate_data is described in a hash.


OS

macOS

Language version

ruby 3.2.5

Library version

13.1.1, 13.1.0

API version

2024-10-28.acacia

Additional context

No response

@airjoshb airjoshb added the bug label Nov 8, 2024
@remi-stripe
Copy link
Contributor

@airjoshb Can you share the exact code you are using end-to-end to reproduce this? The code you shared looks like part of our Test suite so I'm not really grasping what the bug is

@remi-stripe remi-stripe self-assigned this Nov 9, 2024
@airjoshb
Copy link
Author

airjoshb commented Nov 9, 2024

Sorry for the confusion @remi-stripe, I was using the test code to point out where the v1 error was coming from. Here is my code and I suspect it is some sort of syntax change from a previous version as it was working before I did a long overdue upgrade.

checkout_session = Stripe::Checkout::Session.create({
      line_items: line_items,
      mode: mode,
      customer_creation: customer_creation,
      allow_promotion_codes: true,
      phone_number_collection: {
        enabled: true
      },
      shipping_address_collection: {
        allowed_countries: ['US'],
      },
      shipping_options: [
        {
          shipping_rate_data: {
            type: 'fixed_amount',
            fixed_amount: {
              amount: 500,
              currency: 'usd',
            },
            display_name: 'Local Delivery or CA Ship',
            delivery_estimate: {
              minimum: {
                unit: 'business_day',
                value: 1,
              },
              maximum: {
                unit: 'business_day',
                value: 2,
              },
            },
          },
        },
        {
          shipping_rate_data: {
            type: 'fixed_amount',
            fixed_amount: {
              amount: 1100,
              currency: 'usd',
            },
            display_name: 'Ship outside CA',
            delivery_estimate: {
              minimum: {
                unit: 'business_day',
                value: 2,
              },
              maximum: {
                unit: 'business_day',
                value: 3,
              },
            },
          },  
        }
      ],
      consent_collection: {
        promotions: 'auto',
      },
      custom_fields: [
        {
          key: 'pickup',
          label: {type: 'custom', custom: 'Pickup Location'},
          optional: true,
          type: 'dropdown',
          dropdown: {
            options: 
              shipping
          },
        },
      ],
      success_url: cart_success_url,
      cancel_url:  cart_cancel_url,
    })

@remi-stripe
Copy link
Contributor

The code you shared isn't sufficient to reproduce unfortunately. Multiple of those lines reference variables that aren't set first so I am not sure how to reproduce.
I tried similar code on my own account with 13.1.0 and it does work as expected and doesn't error about the /v1/ part.

My gut says that the code erroring is not what you think it is, that Checkout Session creation works properly and something else in your code is erroring or failing. Can you try and provide a really simple end to end reproduction script with clear logs showing which part is crashing.

I did look into our logs and I see some requests where the parameters look like this:

  success_url: "<redacted>",
  v1: {
    0: {
      shipping_rate_data: {
        ...
    },
    1: {
      shipping_rate_data: {
        ...
      },
    },
  },
}

So right now it does look like your own code is passing a parameter/hash named v1 instead of the word shipping_options

@airjoshb
Copy link
Author

airjoshb commented Nov 9, 2024

I hear ya, @remi-stripe, however, if I replace this block,

shipping_options: [
        {
          shipping_rate_data: {
            type: 'fixed_amount',
            fixed_amount: {
              amount: 500,
              currency: 'usd',
            },
            display_name: 'Local Delivery or CA Ship',
            delivery_estimate: {
              minimum: {
                unit: 'business_day',
                value: 1,
              },
              maximum: {
                unit: 'business_day',
                value: 2,
              },
            },
          },
        },
        {
          shipping_rate_data: {
            type: 'fixed_amount',
            fixed_amount: {
              amount: 1100,
              currency: 'usd',
            },
            display_name: 'Ship outside CA',
            delivery_estimate: {
              minimum: {
                unit: 'business_day',
                value: 2,
              },
              maximum: {
                unit: 'business_day',
                value: 3,
              },
            },
          },  
        }
      ],

with

shipping_options: [ { shipping_rate: "shr_XXXXXXLHQPVTKPLFvTR5lA1s" }],

It works perfectly fine, so there doesn't seem to be another place where v1 is being passed except by the url the gem is posting from.

@remi-stripe
Copy link
Contributor

@airjoshb Can I ask you to share an exact script to reproduce this? Your earlier example had local variables that don't exist. Unfortunately without a clear repro I'm coming up empty right now on what could cause this.
Feel free to use the default API key we use in our docs: sk_test_4eC39HqLyjWDarjtT1zdp7dc so that we can run the exact same code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants