WordPress / wordcamp.org

WordCamps are casual, locally-organized conferences covering everything related to WordPress.
https://wordcamp.org
131 stars 74 forks source link

Using `[` in ticket names created with Camptix causes an error with the Stripe API. #1270

Closed hideokamoto closed 8 months ago

hideokamoto commented 8 months ago

Describe the bug

When using Stripe payment for ticket purchases in Camptix, if the ticket name contains [, an error occurs in the Stripe API response. This is because the Stripe API specification interprets the string inside [] as an object key. To resolve this issue, the clean_metadata function needs to replace [] with another character like ().

To reproduce

The ticket name needs to be included in the metadata of the Stripe Payment Intent object when creating Stripe Checkout Sessions API. e.g.: $args['payment_intent_data']['metadata']['6/2 [Sponsor ticket]'] = '1';

**Expected Behavior The ticket name needs to be included in the metadata of the Stripe Payment Intent object when creating Stripe Checkout Sessions API. e.g.: $args['payment_intent_data']['metadata']['6/2 [Sponsor ticket]'] = '1';

Actual Behavior**

Due to the Stripe API specification, a text inside the [] will be converted to an object key like the following:

$args['payment_intent_data']['metadata']['6/2 [Sponsor ticket]'] = '1';
->
{
  "metadata": {
    "6/2": {
      "Sponsor ticket": "1"
    }
  }
}

Suggestion In the clean_metadata function, we may need to replace the [] string with another character like () instead.

$key = $this->trim_string( $key, 40, '' );
$key = str_replace( '[', '(', str_replace( ']', ')', $key ) );

When we avoid passing the [] string as the key of the metadata, the Stripe API request will work correctly.

This idea seems reasonable, and if you approve, I'll proceed with creating a new pull request for this.

Screenshots

If applicable, add screenshots to help explain your problem.

スクリーンショット 2024-03-18 16 38 23

WordCamp

If this is a problem on a specific WordCamp's site, list the site or page URL here.

At the WordCamp Kansai 2024, we suffered from this error: https://kansai.wordcamp.org/2024/wp-admin/post.php?post=3772&action=edit

スクリーンショット 2024-03-18 16 39 59

System (please complete the following information):

Security Issues

To report a security issue, please visit the WordPress HackerOne program: https://hackerone.com/wordpress.

dd32 commented 8 months ago

I think this is something that needs to be raised with Stripe, as to whether it's a bug on their platform, as using square brackets in their UI also results in a.. less than expected, unexpected request error.

https://github.com/WordPress/wordcamp.org/assets/767313/a4175f16-9aef-47d2-bb93-9b46acbbad88

I've raised a support ticket with them, as [] are not documented as being invalid in the field.