#Rian ROnald

1 messages · Page 1 of 1 (latest)

latent wigeonBOT
signal jacinth
#

Hi 👋

Do you mean for the Checkout Session?

#

Have you tested this?

calm tartan
#

yes

#
"custom_fields": [
    {
      "dropdown": null,
      "key": "discordid",
      "label": {
        "custom": "Discord ID",
        "type": "custom"
      },
      "numeric": null,
      "optional": false,
      "text": {
        "maximum_length": null,
        "minimum_length": null,
        "value": "962801895188090960"
      },
      "type": "text"
    }
  ],
signal jacinth
#

So when you create a checkout session with this in your code and you attempt to access custom_fields[0], what do you get?

calm tartan
#

Nothing

signal jacinth
#

No index error?

calm tartan
#

nope

signal jacinth
#

And when you attempt custom_fields[1] you see the field object?

calm tartan
#

Nothing

signal jacinth
#

So then we have to ask if the custom_fields property is something the object exposes after you pass it.

#

What is behind your question? What are you trying to do?

calm tartan
#
$stripe = new \Stripe\StripeClient('SECERE EY');

$checkoutSessions = $stripe->checkout->sessions->all(['limit' => 3]);

$found = false;

foreach ($checkoutSessions as $checkoutSession) {
    $discordID = $checkoutSession->custom_fields[0]->text->value;

    if ($discordID === $discord_id) {
        $found = true;

        include('includes/config.php');

        $user_query = "UPDATE users SET paid = 1 WHERE discordID = :discordID";
        $stmt = $pdo->prepare($user_query);
        $stmt->bindParam(':discordID', $discordID, PDO::PARAM_INT);
    

        $stmt->execute();
        
        $url = "WEBTHIng";
        
        $hookObject = json_encode([
            "embeds" => [
              
                [
                    "title" => "Purchase has been made!",
        
                    "type" => "rich",
        
                    "color" => hexdec( "3cb2f7" ),
        
        
                    "fields" => [
                        [
                            "name" => "Discord Tag",
                            "value" => "<@" . $discord_id . ">",
                            "inline" => true
                        ],
                        [
                            "name" => "Discord ID",
                            "value" => "$discord_id",
                            "inline" => true
                        ],
                    ]
                ]
            ]
        
        ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
        
        $ch = curl_init();
        
        curl_setopt_array( $ch, [
            CURLOPT_URL => $url,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $hookObject,
            CURLOPT_HTTPHEADER => [
                "Content-Type: application/json"
            ]
        ]);
        
        $response = curl_exec( $ch );
        curl_close( $ch );

        break; 
    }

#

What im trying to do is when a user does a purchase it redirects them to the link that has this code and it searches for their id they put in the field with the session id then updates the db and sends a webhook

signal jacinth
#

Okay I'm spinning up my own example to test this out

#

Okay I am getting my custom fields in the returned Checkout Session

#

And access them using a zero index