#santiago-checkout-customfields

1 messages · Page 1 of 1 (latest)

gritty ospreyBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

barren gate
#
require '../vendor/autoload.php';
    // Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('');


// You can find your endpoint's secret in your webhook settings
$endpoint_secret = "whsec_";

//error log for checking output 
$log_file = "errors.log";

$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;

try {
  $event = \Stripe\Webhook::constructEvent(
    $payload, $sig_header, $endpoint_secret
    
  );
  error_log($payload);
  error_log($event);
} catch(\UnexpectedValueException $e) {
  // Invalid payload
  error_log("\n\nInvalid Payload!\n\n",3,$log_file);
  http_response_code(400);
  exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
  // Invalid signature
  error_log("\n\nInvalid Signature!\n\n",3,$log_file);
  http_response_code(400);
  exit();
}
error_log($event);
//error_log("\n\nPassed signature verification!\n\n",3,$log_file);
http_response_code(200);
?>```
potent bolt
#

Hi 👋

Can you summarize what you mean by the "try/catch"

#

If you mean that

 $event = \Stripe\Webhook::constructEvent(
    $payload, $sig_header, $endpoint_secret
    
  );

is what is throwing the error, that is expected. That is where the webhook signature is verified

barren gate
#

apparently it is or is not creating the event? because i try to error_log event or anything and is not printing anything in that block

#

after that line

potent bolt
#

I see you have multiple catch blocks for specific exceptions. Can you try implementing on generic one and logging the value of $e to the console?

barren gate
#

sure, is just catch (Exception $e) correct ?

potent bolt
#

Yeah and log the $e

barren gate
#

ok, now im back to invalid signature let me double check my endpoint secret, i shouldn't have change it but i'll check again

#

ok so this code gives me passed signature verification

potent bolt
#

Great! You are creating valid events now?

barren gate
#

<?php
require '../vendor/autoload.php';
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('sk_test_');

// You can find your endpoint's secret in your webhook settings
$endpoint_secret = "whsec_";

//error log for checkign output
$log_file = "errors.log";

$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;

try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret

);
} catch(\UnexpectedValueException $e) {
// Invalid payload
error_log("\n\nInvalid Payload!\n\n",3,$log_file);
http_response_code(400);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
error_log("\n\nInvalid Signature!\n\n",3,$log_file);
http_response_code(400);
exit();
}
catch (Exception $e){
error_log($e,3,$log_file);
}
error_log($event);
error_log("\n\nPassed signature verification!\n\n",3,$log_file);
http_response_code(200);
?>

#

not yet

#

this is basically from the demo,

#
  $event = \Stripe\Webhook::constructEvent(
    $payload, $sig_header, $endpoint_secret
    
  );
  error_log($event); ```
#

this part won't show event. do i have to put everything outside the try block? i gues s ?

potent bolt
#

Is there any part of your code that is logging anything at this point?

barren gate
#

shouldnt it log event? i tried logging tester before the event call and worked.

#

let me try the other way

potent bolt
#

Can you just print the event? I'm trying to understand if the constructEvent function is actually succeeding

barren gate
#

yes, that was i wast rying to find out

#

apparently it is working, now

#

i did forget to put 3,$log_file on that one, that's on me

#

but yes it is succeeding

#

this worked now

#
  $event = \Stripe\Webhook::constructEvent(
    $payload, $sig_header, $endpoint_secret
    
  );
  error_log($event,3,$log_file);```
potent bolt
#

Wonderful!

barren gate
#

there is no parameter /custom one that i can send to checkout session hidden right? customer uploading a picture and I want picture to be processed after the payment is done, and i'm sending it as a data/image64 so ideally would like the webhook to process it but if not, is ok i'll just figure out another way

potent bolt
#

I'm not sure I understand what you mean. Do you have an example Checkout Session ID or API request ID I can look at?

barren gate
#

I'm using stripe=hosted for payment. and this is php code, so far just tsting functionality so not much is added yet. and the redirect is done via javascript.

potent bolt
#

Okay but any tine you create a Checkout Session with Stripe PHP it will create an API request with an ID you can find in your Developer logs in the Stripe Dashboard

barren gate
#
require '../vendor/autoload.php';
$stripe = new \Stripe\StripeClient('sk_test_');

$data = json_decode(file_get_contents("php://input"));
if(!isset($data)){
    echo "no data";
    //header('Location: /local_upload/');
}
else {
     session_start();
    //add check if valid json data and all json keys are non null  
    //after check do this
    $_SESSION['json'] = $data;
    $checkout_session = $stripe->checkout->sessions->create([
  'line_items' => [[
    'price_data' => [
      'currency' => 'usd',
      'product_data' => [
        'name' => 'Hosting Ads Promo',
      ],
      'unit_amount' => $data->price,
    ],
    'quantity' => $data->quantity,
  ]],
  'mode' => 'payment',
  'success_url' => 'http://guesthostad.lcsitmedia.com/success.php?session_id={CHECKOUT_SESSION_ID}',
  'cancel_url' => 'http://guesthostad.lcsitmedia.com/',
]);

echo $checkout_session->url;
}?>```
#

yes, i see the session id and redirects to success page with session id, I jus wonder if there is any specific thing i can send direct to the webhook, maybe in 'line_items' other than product dat name, unit amount quantity'. send some other data so webhook can process at the end.. sending it on the end..

potent bolt
#

You cannot send anything direct to the webhook. The Webhook event will contain the Checkout Session object.

I'm not sure I'm grasping what you are trying to do though

barren gate
#

send custom data on teh checkout session, for example, it has 'line_item's and 'unit_amount' etc, is there any other parameters i can use on the checkout session

#

oh i just saw

gritty ospreyBOT
barren gate
#

custom fields

potent bolt
barren gate
#

awesome thank you

#

i think that might work

potent bolt
#

Just be sure to be aware of the restrictions of custom_fields. We only accept text, numeric, or dropdown fields

ancient schooner
#

santiago-checkout-customfields

barren gate
#

ok sounds good

#

and those will show on checkout page correct

ancient schooner
#

@barren gate yes, but really just try it yourself, way faster than trying to guess or back and forth with us. It'll click quickly