Fix 3D secure

convett to dolibarr standard stripe payment metadata
This commit is contained in:
ptibogxiv 2018-08-06 19:21:12 +02:00 committed by GitHub
parent e1877625a0
commit e84018ac15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,11 +42,13 @@ if (isset($_GET['connect'])){
{
$endpoint_secret = $conf->global->STRIPE_TEST_WEBHOOK_CONNECT_KEY;
$service = 'StripeTest';
$servicestatus = 0;
}
else
{
$endpoint_secret = $conf->global->STRIPE_LIVE_WEBHOOK_CONNECT_KEY;
$service = 'StripeLive';
$servicestatus = 1;
}
}
else {
@ -54,11 +56,13 @@ else {
{
$endpoint_secret = $conf->global->STRIPE_TEST_WEBHOOK_KEY;
$service = 'StripeTest';
$servicestatus = 0;
}
else
{
$endpoint_secret = $conf->global->STRIPE_LIVE_WEBHOOK_KEY;
$service = 'StripeLive';
$servicestatus = 1;
}
}
$payload = @file_get_contents("php://input");
@ -227,19 +231,37 @@ elseif ($event->type == 'charge.failed') {
}
elseif (($event->type == 'source.chargeable') && ($event->data->object->type == 'three_d_secure') && ($event->data->object->three_d_secure->authenticated==true)) {
$stripe=new Stripe($db);
$charge=$stripe->CreatePaymentStripe($event->data->object->amount/100,$event->data->object->currency,$event->data->object->metadata->source,$event->data->object->metadata->idsource,$event->data->object->id,$event->data->object->metadata->customer,$stripe->getStripeAccount($service));
$fulltag=$event->data->object->metadata->FULLTAG;
// Save into $tmptag all metadata
$tmptag=dolExplodeIntoArray($fulltag,'.','=');
if (! empty($tmptag['ORD'])){
$order=new Commande($db);
$order->fetch('',$tmptag['ORD']);
$origin='order';
$item=$order->id;
} elseif (! empty($tmptag['INV'])) {
$invoice = new Facture($db);
$invoice->fetch('',$tmptag['INV']);
$origin='invoice';
$item=$invoice->id;
}
$stripe=new Stripe($db);
$stripeacc = $stripe->getStripeAccount($service); // Stripe OAuth connect account of dolibarr user (no network access here)
$stripecu = $stripe->getStripeCustomerAccount($tmptag['CUS'], $servicestatus); // Get thirdparty cu_...
$charge=$stripe->createPaymentStripe($event->data->object->amount/100,$event->data->object->currency,$origin,$item,$event->data->object->id,$stripecu,$stripeacc,$servicestatus);
if (isset($charge->id) && $charge->statut=='error'){
$msg=$charge->message;
$code=$charge->code;
$error++;
}
elseif (isset($charge->id) && $charge->statut=='success' && $event->data->object->metadata->source=='order') {
$order=new Commande($db);
$order->fetch($event->data->object->metadata->idsource);
}
elseif (isset($charge->id) && $charge->statut=='success' && (! empty($tmptag['ORD']))) {
//$order=new Commande($db);
//$order->fetch('',$tmptag['ORD']);
$invoice = new Facture($db);
$idinv=$invoice->createFromOrder($order);
$idinv=$invoice->createFromOrder($order,$user);
if ($idinv > 0)
{
@ -265,7 +287,7 @@ elseif (($event->type == 'source.chargeable') && ($event->data->object->type ==
if (!$error){
$datepaye = dol_now();
$paiementcode ="CB";
$paymentType ="CB";
$amounts=array();
$amounts[$invoice->id] = $total;
$multicurrency_amounts=array();
@ -274,7 +296,7 @@ elseif (($event->type == 'source.chargeable') && ($event->data->object->type ==
$paiement->datepaye = $datepaye;
$paiement->amounts = $amounts; // Array with all payments dispatching
$paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching
$paiement->paiementid = dol_getIdFromCode($db,$paiementcode,'c_paiement');
$paiement->paiementid = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1);
$paiement->num_paiement = $charge->message;
$paiement->note = '';
}