Clean code
This commit is contained in:
parent
31002317ee
commit
b78eebaae2
@ -41,7 +41,8 @@ STRIPE_LIVE_WEBHOOK_KEY=Webhook live key
|
|||||||
ONLINE_PAYMENT_WAREHOUSE=Stock to use for stock decrease when online payment is done<br>(TODO When option to decrease stock is done on an action on invoice and the online payment generate itself the invoice ?)
|
ONLINE_PAYMENT_WAREHOUSE=Stock to use for stock decrease when online payment is done<br>(TODO When option to decrease stock is done on an action on invoice and the online payment generate itself the invoice ?)
|
||||||
StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode)
|
StripeLiveEnabled=Stripe live enabled (otherwise test/sandbox mode)
|
||||||
StripeImportPayment=Import Stripe payments
|
StripeImportPayment=Import Stripe payments
|
||||||
ExampleOfTestCreditCard=Example of credit card for test: %s => valid, %s => error CVC, %s => expired, %s => charge fails
|
ExampleOfTestCreditCard=Example of credit card for SEPA test: %s => valid, %s => error CVC, %s => expired, %s => charge fails
|
||||||
|
ExampleOfTestBankAcountForSEPA=Example of bank account BAN for direct debit test: %s
|
||||||
StripeGateways=Stripe gateways
|
StripeGateways=Stripe gateways
|
||||||
OAUTH_STRIPE_TEST_ID=Stripe Connect Client ID (ca_...)
|
OAUTH_STRIPE_TEST_ID=Stripe Connect Client ID (ca_...)
|
||||||
OAUTH_STRIPE_LIVE_ID=Stripe Connect Client ID (ca_...)
|
OAUTH_STRIPE_LIVE_ID=Stripe Connect Client ID (ca_...)
|
||||||
@ -70,5 +71,8 @@ ToOfferALinkForLiveWebhook=Link to setup Stripe WebHook to call the IPN (live mo
|
|||||||
PaymentWillBeRecordedForNextPeriod=Payment will be recorded for the next period.
|
PaymentWillBeRecordedForNextPeriod=Payment will be recorded for the next period.
|
||||||
ClickHereToTryAgain=<a href="%s">Click here to try again...</a>
|
ClickHereToTryAgain=<a href="%s">Click here to try again...</a>
|
||||||
CreationOfPaymentModeMustBeDoneFromStripeInterface=Due to Strong Customer Authentication rules, creation of a card must be done from Stripe backoffice. You can click here to switch on Stripe customer record: %s
|
CreationOfPaymentModeMustBeDoneFromStripeInterface=Due to Strong Customer Authentication rules, creation of a card must be done from Stripe backoffice. You can click here to switch on Stripe customer record: %s
|
||||||
TERMINAL_LOCATION=Location (address) for terminals
|
STRIPE_CARD_PRESENT=Card Present for Stripe Terminals
|
||||||
|
TERMINAL_LOCATION=Location (address) for Stripe Terminals
|
||||||
RequestDirectDebitWithStripe=Request Direct Debit with Stripe
|
RequestDirectDebitWithStripe=Request Direct Debit with Stripe
|
||||||
|
STRIPE_SEPA_DIRECT_DEBIT=Enable the Direct Debit payments through Stripe
|
||||||
|
|
||||||
@ -427,31 +427,16 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activate Payment Request API
|
print '<tr class="oddeven"><td>';
|
||||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
|
print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
|
||||||
print '<tr class="oddeven"><td>';
|
if ($conf->use_javascript_ajax) {
|
||||||
print $langs->trans("STRIPE_PAYMENT_REQUEST_API").' ?? Not used, what is it for ??</td><td>';
|
|
||||||
if ($conf->use_javascript_ajax) {
|
|
||||||
print ajax_constantonoff('STRIPE_PAYMENT_REQUEST_API');
|
|
||||||
} else {
|
|
||||||
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
|
||||||
print $form->selectarray("STRIPE_PAYMENT_REQUEST_API", $arrval, getDolGlobalString('STRIPE_PAYMENT_REQUEST_API'));
|
|
||||||
}
|
|
||||||
print '</td></tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activate SEPA DIRECT_DEBIT
|
|
||||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
|
|
||||||
print '<tr class="oddeven"><td>';
|
|
||||||
print $langs->trans("STRIPE_SEPA_DIRECT_DEBIT").'</td><td>';
|
|
||||||
if ($conf->use_javascript_ajax) {
|
|
||||||
print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
|
print ajax_constantonoff('STRIPE_SEPA_DIRECT_DEBIT');
|
||||||
} else {
|
} else {
|
||||||
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
|
||||||
print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
|
print $form->selectarray("STRIPE_SEPA_DIRECT_DEBIT", $arrval, getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT'));
|
||||||
}
|
|
||||||
print '</td></tr>';
|
|
||||||
}
|
}
|
||||||
|
print '</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
// Activate Klarna
|
// Activate Klarna
|
||||||
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
|
if ($conf->global->MAIN_FEATURES_LEVEL >= 2) { // TODO Not used by current code
|
||||||
@ -608,6 +593,12 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/onlinepaymentlinks.tpl.php';
|
|||||||
|
|
||||||
print info_admin($langs->trans("ExampleOfTestCreditCard", '4242424242424242 (no 3DSecure) or 4000000000003063 (3DSecure required) or 4000002760003184 (3DSecure2 required on all transaction) or 4000003800000446 (3DSecure2 required, the off-session allowed)', '4000000000000101', '4000000000000069', '4000000000000341'));
|
print info_admin($langs->trans("ExampleOfTestCreditCard", '4242424242424242 (no 3DSecure) or 4000000000003063 (3DSecure required) or 4000002760003184 (3DSecure2 required on all transaction) or 4000003800000446 (3DSecure2 required, the off-session allowed)', '4000000000000101', '4000000000000069', '4000000000000341'));
|
||||||
|
|
||||||
|
if (getDolGlobalString('STRIPE_SEPA_DIRECT_DEBIT')) {
|
||||||
|
print info_admin($langs->trans("ExampleOfTestBankAcountForSEPA", 'AT611904300234573201 (pending->succeed) or AT861904300235473202 (pending->failed)'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!empty($conf->use_javascript_ajax)) {
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
print "\n".'<script type="text/javascript">';
|
print "\n".'<script type="text/javascript">';
|
||||||
print '$(document).ready(function () {
|
print '$(document).ready(function () {
|
||||||
|
|||||||
@ -906,7 +906,7 @@ class Stripe extends CommonObject
|
|||||||
global $conf, $user, $langs;
|
global $conf, $user, $langs;
|
||||||
$sepa = null;
|
$sepa = null;
|
||||||
|
|
||||||
$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.iban_prefix"; // stripe_card_ref is src_ for sepa
|
$sql = "SELECT sa.stripe_card_ref, sa.proprio, sa.iban_prefix, sa.rum"; // stripe_card_ref is 'src_...' for Stripe SEPA
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as sa";
|
$sql .= " FROM ".MAIN_DB_PREFIX."societe_rib as sa";
|
||||||
$sql .= " WHERE sa.rowid = ".((int) $object->id); // We get record from ID, no need for filter on entity
|
$sql .= " WHERE sa.rowid = ".((int) $object->id); // We get record from ID, no need for filter on entity
|
||||||
$sql .= " AND sa.type = 'ban'"; //type ban to get normal bank account of customer (prelevement)
|
$sql .= " AND sa.type = 'ban'"; //type ban to get normal bank account of customer (prelevement)
|
||||||
@ -950,13 +950,35 @@ class Stripe extends CommonObject
|
|||||||
$dataforcard = array(
|
$dataforcard = array(
|
||||||
'type'=>'sepa_debit',
|
'type'=>'sepa_debit',
|
||||||
"sepa_debit" => array('iban' => $iban),
|
"sepa_debit" => array('iban' => $iban),
|
||||||
'currency' => 'eur',
|
'currency' => strtolower($conf->currency),
|
||||||
'usage' => 'reusable',
|
'usage' => 'reusable',
|
||||||
'owner' => array(
|
'owner' => array(
|
||||||
'name' => $soc->name,
|
'name' => $soc->name,
|
||||||
),
|
),
|
||||||
"metadata" => array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>$ipaddress)
|
"metadata" => array(
|
||||||
|
'dol_type'=>$object->element,
|
||||||
|
'dol_id'=>$object->id,
|
||||||
|
'dol_version'=>DOL_VERSION,
|
||||||
|
'dol_entity'=>$conf->entity,
|
||||||
|
'ipaddress'=>$ipaddress
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
// Complete owner name
|
||||||
|
if (!empty($soc->town)) {
|
||||||
|
$dataforcard['owner']['address']['city']=$soc->town;
|
||||||
|
}
|
||||||
|
if (!empty($soc->country_code)) {
|
||||||
|
$dataforcard['owner']['address']['country']=$soc->country_code;
|
||||||
|
}
|
||||||
|
if (!empty($soc->address)) {
|
||||||
|
$dataforcard['owner']['address']['line1']=$soc->address;
|
||||||
|
}
|
||||||
|
if (!empty($soc->zip)) {
|
||||||
|
$dataforcard['owner']['address']['postal_code']=$soc->zip;
|
||||||
|
}
|
||||||
|
if (!empty($soc->state)) {
|
||||||
|
$dataforcard['owner']['address']['state']=$soc->state;
|
||||||
|
}
|
||||||
|
|
||||||
//$a = \Stripe\Stripe::getApiKey();
|
//$a = \Stripe\Stripe::getApiKey();
|
||||||
//var_dump($a);var_dump($stripeacc);exit;
|
//var_dump($a);var_dump($stripeacc);exit;
|
||||||
@ -974,17 +996,18 @@ class Stripe extends CommonObject
|
|||||||
$stripeacc = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
|
$stripeacc = $stripearrayofkeysbyenv[$servicestatus]['secret_key'];
|
||||||
|
|
||||||
dol_syslog("Try to create sepa_debit with data = ".json_encode($dataforcard));
|
dol_syslog("Try to create sepa_debit with data = ".json_encode($dataforcard));
|
||||||
|
// TODO Replace with PaymentIntent. Can use $stripe->getPaymentIntent ?
|
||||||
$s = new \Stripe\StripeClient($stripeacc);
|
$s = new \Stripe\StripeClient($stripeacc);
|
||||||
$sepa = $s->sources->create($dataforcard);
|
$sepa = $s->sources->create($dataforcard);
|
||||||
if (!$sepa) {
|
if (!$sepa) {
|
||||||
$this->error = 'Creation of sepa_debit on Stripe has failed';
|
$this->error = 'Creation of sepa_debit on Stripe has failed';
|
||||||
} else {
|
} else {
|
||||||
// association du client avec cette source de paimeent
|
// link customer and src
|
||||||
$cs = $cu->createSource($cu->id, array('source' => $sepa->id));
|
$cs = $cu->createSource($cu->id, array('source' => $sepa->id));
|
||||||
if (!$cs) {
|
if (!$cs) {
|
||||||
$this->error = 'Link SEPA <-> Customer failed';
|
$this->error = 'Link SEPA <-> Customer failed';
|
||||||
} else {
|
} else {
|
||||||
dol_syslog("Try to create sepa_debit 3");
|
dol_syslog("Update the payment request");
|
||||||
// print json_encode($sepa);
|
// print json_encode($sepa);
|
||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user