I created a webhook to get informations about checkout sessions :
public function stripeWebhookCheckout(Request $request)
{
\Stripe\Stripe::setApiKey(env("STRIPE_SECRET"));
// You can find your endpoint's secret in your webhook settings
$endpoint_secret = 'whsec_fVBkAmCztUTacQKZiyjmcq6QQrl8lKL1';
$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
http_response_code(400);
exit();
} catch (\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
$session = $event->data->object;
// Fulfill the purchase...
handle_checkout_session($session);
$stripeSessionId = $session['id'];
if (isset($stripeSessionId)) {
$payment = Payment::where('stripe_sessioncheckout_id', '=', $stripeSessionId)->first();
$payment->status = "success";
$payment->data = $session;
$payment->save();
}
}
http_response_code(200);
}
I use stripe-cli to test my webhook in local. And i have this kind of result
$ stripe listen --forward-to jvlb.test/api/stripe/webhook/checkout
> Ready! Your webhook signing secret is whsec_sc9Gh9A6zx3IOfBpH62F9DdPYIhSUYtw (^C to quit)
2019-11-28 16:19:06 --> charge.succeeded [evt_1FjsW5FIYszmshR0eGSB9GDo]
2019-11-28 16:19:06 <-- [400] GET https://jvlb.test/api/stripe/webhook/checkout [evt_1FjsW5FIYszmshR0eGSB9GDo]
To debug it i changes the http_response_code(400) and I realised it generate a SignatureVerificationException.
My question is, how can i debug this ? Is it the $_SERVER['HTTP_STRIPE_SIGNATURE'] who is wrong ?
Thanks
i found a solution, if it can help people in the future :
I made a mistake in the way i use stripe-cli, i forgot "https://".
The good way is :
stripe listen --forward-to https://jvlb.test/api/stripe/webhook/checkout
And then i had few error of code to manage. I just used the tail command on my log file
tail -f storage/logs/laravel-2019-11-29.log
I'm trying to redirect after executing some code with flash message then apache hang and sent error
Connot modify header information - headers already sent
public function convert_to_invoice($id)
{
if (!has_permission('invoices', '', 'create')) {
access_denied('invoices');
}
if (!$id) {
die('No estimate found');
}
$draft_invoice = false;
if ($this->input->get('save_as_draft')) {
$draft_invoice = true;
}
$invoiceid = $this->estimates_model->convert_to_invoice($id, false, $draft_invoice);
if ($invoiceid) {
$this->session->set_flashdata('message-success','estimate_convert_to_invoice_successfully');
redirect('invoices/list_invoices/' . $invoiceid);
} else {
if ($this->session->has_userdata('estimate_pipeline') && $this->session->userdata('estimate_pipeline') == 'true') {
$this->session->set_flashdata('estimateid', $id);
}
if ($this->set_estimate_pipeline_autoload($id)) {
redirect($_SERVER['HTTP_REFERER']);
} else {
redirect(admin_url('estimates/list_estimates/' . $id));
}
}
}
As redirect uses headers to perform its task nothing can be outputted before it is called. I don't see anything that would cause output except:
if (!has_permission('invoices', '', 'create')) {
access_denied('invoices'); // exits?
}
if (!$id) {
die('No estimate found');
}
However both seem to exit so the redirect stage shouldn't be reached.
I would suggest removing the redirects temporarily, running the script, and seeing what is outputting. You can then remove/silence those offending pieces of code and re-institute the redirects. It might be as simple as an error outputting.
I just pulled some updates in a repository. Then when I use the command "php artisan migrate" it gives me an error. See the screenshot below.
How can I fix this?
Or what seems to be causing this?
Thank you!
Edit
Heres the code for Util.php. But I don't think I should be messing with it since it came from vendors directory.
<?php
namespace Monolog\Handler\Curl;
class Util
{
private static $retriableErrorCodes = array(
CURLE_COULDNT_RESOLVE_HOST,
CURLE_COULDNT_CONNECT,
CURLE_HTTP_NOT_FOUND,
CURLE_READ_ERROR,
CURLE_OPERATION_TIMEOUTED,
CURLE_HTTP_POST_ERROR,
CURLE_SSL_CONNECT_ERROR,
);
public static function execute($ch, $retries = 5, $closeAfterDone = true)
{
while ($retries--) {
if (curl_exec($ch) === false) {
$curlErrno = curl_errno($ch);
if (false === in_array($curlErrno, self::$retriableErrorCodes, true) || !$retries) {
$curlError = curl_error($ch);
if ($closeAfterDone) {
curl_close($ch);
}
throw new \RuntimeException(sprintf('Curl error (code %s): %s', $curlErrno, $curlError));
}
continue;
}
if ($closeAfterDone) {
curl_close($ch);
}
break;
}
}
}
Not a permanent fix, but rather than have this you can commented it out throw new \RuntimeException(sprintf('Curl error (code %d): %s', $curlErrno, $curlError)); and the I had return true;
I have this code
function checkIBAN($iban)
{
$iban = strtolower(str_replace(' ','',$iban));
$Countries = array('al'=>28,'ad'=>24,'at'=>20,'az'=>28,'bh'=>22,'be'=>16,'ba'=>20,'br'=>29,'bg'=>22,'cr'=>21,'hr'=>21,'cy'=>28,'cz'=>24,'dk'=>18,'do'=>28,'ee'=>20,'fo'=>18,'fi'=>18,'fr'=>27,'ge'=>22,'de'=>22,'gi'=>23,'gr'=>27,'gl'=>18,'gt'=>28,'hu'=>28,'is'=>26,'ie'=>22,'il'=>23,'it'=>27,'jo'=>30,'kz'=>20,'kw'=>30,'lv'=>21,'lb'=>28,'li'=>21,'lt'=>20,'lu'=>20,'mk'=>19,'mt'=>31,'mr'=>27,'mu'=>30,'mc'=>27,'md'=>24,'me'=>22,'nl'=>18,'no'=>15,'pk'=>24,'ps'=>29,'pl'=>28,'pt'=>25,'qa'=>29,'ro'=>24,'sm'=>27,'sa'=>24,'rs'=>22,'sk'=>24,'si'=>19,'es'=>24,'se'=>24,'ch'=>21,'tn'=>24,'tr'=>26,'ae'=>23,'gb'=>22,'vg'=>24);
$Chars = array('a'=>10,'b'=>11,'c'=>12,'d'=>13,'e'=>14,'f'=>15,'g'=>16,'h'=>17,'i'=>18,'j'=>19,'k'=>20,'l'=>21,'m'=>22,'n'=>23,'o'=>24,'p'=>25,'q'=>26,'r'=>27,'s'=>28,'t'=>29,'u'=>30,'v'=>31,'w'=>32,'x'=>33,'y'=>34,'z'=>35);
try{
$cntr=(in_array(substr($iban,0,2),$Countries)) ? $Countries[substr($iban,0,2)] : false;
if(strlen($iban) == $cntr){
$MovedChar = substr($iban, 4).substr($iban,0,4);
$MovedCharArray = str_split($MovedChar);
$NewString = "";
foreach($MovedCharArray AS $key => $value){
if(!is_numeric($MovedCharArray[$key])){
$MovedCharArray[$key] = $Chars[$MovedCharArray[$key]];
}
$NewString .= $MovedCharArray[$key];
}
if(bcmod($NewString, '97') == 1)
{
return TRUE;
}
else{
return FALSE;
}
}
else{
return FALSE;
}
}catch (Exception $e) {
report($e);
return false;
}
}
And I receive this exception in Laravel
{message: "Undefined offset: 21", exception: "ErrorException",…}
exception
:
"ErrorException"
"Undefined offset: 21" in this string $Countries[substr($iban,0,2)]
How can I run from Exception and receive just a false in this case? Because of that fact that my function which is checking iban must receive only true or false not an Exception. If I receive an Exception that is 500error in Ajax
There are quite a few tested iban validation libraries on the packagist.
https://packagist.org/?q=iban&p=0
I'd use one of these instead.
Much better than some crusty code copied off another stackoverflow question.
A "ErrorException" is laravel's error handler turning a php error into an exception. You can avoid the error by adding checks before doing array access.
Consider this example:
$MovedCharArray[$key] = $Chars[$MovedCharArray[$key]];
It assumes that $MovedCharArray has an index of $key and assumes that $Chars has an index of $MovedCharArray[$key]. If any of those don't exist, you'll get that error.
Add some checks before attempting to access those array elements and you can avoid the error.
if(isset($MovedCharArray[$key]) && isset($Chars[$MovedCharArray[$key]])){
$MovedCharArray[$key] = $Chars[$MovedCharArray[$key]];
}else{
//Some error condition you'll need to deal with.
}
The json output is not generated by Ext getcontentbyajax in TYPO3 ver. 4.7. It invokes an 500 Internal server error. In the serverlog i found the error is in line 42 of /lib/class.tx_getcontentbyajax.php.
switch(t3lib_div::_GP('todo')){
I found a 4.7 issue on:
http://lists.typo3.org/pipermail/typo3-german/2012-September/087865.html
t3lib_div::GPvar() changes to t3lib_div::_GP()
When you change all GPvar's to _GP the extension works fine.
Here the changed method main() form /lib/class.tx_getcontentbyajax.php of getcontentbyajax extension:
public function main(){
switch(t3lib_div::_GP('todo')){
case 'pagebrowser':
$href = str_replace(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '', t3lib_div::_GP('href')); // IE6 has problems
$requestedPage = file_get_contents(urldecode(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $href));
/*preg_match('/<div.*?id\=[\"]{0,1}' . t3lib_div::GPvar('part') . '[\"]{0,1}.*?>[\r\n]{0,2}<!--ajaxreplace-->[\s]{0,}(.*?)[\s]{0,}<!--ajaxreplace-->[\r\n]{0,2}<\/div>/s', $requestedPage, $matches);*/
preg_match('/<!--ajaxreplace-->(.*?)<!--ajaxreplace-->/s', $requestedPage, $matchesContent);
preg_match('/<title>(.*?)<\/title>/s', $requestedPage, $matchesTitle);
if(array_key_exists(1, $matchesContent)){
if(array_key_exists(1, $matchesTitle)){
$this->data['title'] = $matchesTitle[1];
}
$this->data['content'] = $matchesContent[1];
$this->data['success'] = true;
} else {
$this->data['content'] = 'An error occured, please reload the site or click this link to load your desired page.';
$this->data['success'] = false;
}
// hook
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['getcontentbyajax']['mainHook'])){
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['getcontentbyajax']['mainHook'] as $_classRef){
$_procObj = & t3lib_div::getUserObj($_classRef);
$this->data = $_procObj->extraGlobalMarkerProcessor($this, $this->data);
}
}
break;
}
echo json_encode($this->data);
}