Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
membrubackend
/
app
/
Helpers
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
connect_user_with_stripe.php
| Size :
6.26
KB
Copy
<?php use Mpociot\VatCalculator\VatCalculator; use App\Models\Package; function validateCUI($instance, $cui){ $blacklisted = [ 'cui' => ['10061498', '24230589', '22098768', '18643343'] ]; if(Str::contains($cui, ['ro', 'RO', 'Ro', 'rO', 'ro ', 'RO ', 'Ro ', 'rO '])){ $replace = [ 'RO'=>'', 'ro'=>'', 'Ro'=>'', 'rO'=>'', 'RO '=>'', 'ro '=>'', 'Ro '=>'', 'rO '=>'' ]; $cui = strtr($cui, $replace ); } if(in_array($cui, $blacklisted['cui'])){ return false; }else{ $instance->update(['cui' => $cui]); return true; } } function createCustomerIntoStripe($instance, $email){ $vatCalculator = new VatCalculator(); if ($instance->country == "RO" || $vatCalculator->shouldCollectVAT($instance->country)) { $instance->update(['vat_percentage' => 19]); }else{ $instance->update(['vat_percentage' => 0]); } if($instance->company_name){ $extraInfoFounded = getNrRegAndAddress($instance); if($extraInfoFounded){ $details = $instance->company_name." (CUI: ".$instance->cui.", Nr. Reg: ".$instance->reg_no.", Adresa: ".$instance->address.")"; }else{ $details = $instance->company_name." (CUI:".$instance->cui.")"; } }else{ $details = $instance->name." (CNP:".$instance->cnp.")"; } try { $customerData = [ 'email' => $email, 'name' => $details, 'phone' => $instance->phone, 'metadata' => [ 'instance_id' => $instance->id, 'CNP' => $instance->cnp, 'CUI' => $instance->cui, 'reg_no' => $instance->reg_no, 'adresa' => $instance->address, ], 'invoice_settings' => [ 'custom_fields' => [ [ 'name' => "Nr.ord.reg.com.", 'value' => "J23/2632/2019" ], [ 'name' => "CUI", 'value' => "RO 41257754" ], [ 'name' => "Adresa", 'value' => "Bd Pipera 1-IA,Voluntari,IF,RO" ], [ 'name' => "Email", 'value' => "contact@tbf.ro" ] ] ], ]; $customer = Stripe::customers()->create($customerData); } catch (Cartalyst\Stripe\Exception\MissingParameterException $e) { return [ 'status' => 'error', 'message' => $e->getMessage() ]; } // check tax id is valid and add to customer if($instance->cui){ $cui = $instance->cui; if( Str::contains($cui, ['ro', 'RO', 'Ro']) ){ $replace = [ 'RO'=>'', 'ro'=>'', 'RO'=>'', 'Ro'=>'', ]; $cui = strtr( $cui, $replace ); } try { $taxID = Stripe::customerTaxIds()->create($customer['id'], [ 'type' => 'eu_vat', 'value' => $cui ]); } catch (Cartalyst\Stripe\Exception\MissingParameterException $e) { // delete old tax ID if(isset($taxID)){ try { Stripe::customerTaxIds()->delete($customer['id'], $taxID['id']); } catch (Cartalyst\Stripe\Exception\MissingParameterException $e) { // } } // send mail with the problematic CUI $customer['cui'] = $instance->cui; // createMail(null, CronjobMail::CUI_ERROR, $customer); } } $instance->update(['stripe_customer_id' => $customer['id']]); return [ 'success' => true ]; } function calculateDiscountBasedOnVoucher($coupon, $package_name, $currency) { $package = Package::where('name',$package_name)->first(); $p_price = $package->price_in_euro; if($currency == 'RON'){ $p_price = $package->price_in_ron; } if($coupon['amount_off']){ $d_price = round($p_price - $coupon['amount_off']/100); }else{ $d_price = round($p_price - ($coupon['percent_off']/100*$p_price)); } return ['package_id' => $package->id, 'price' => $d_price, 'currency' => $currency]; } function getNrRegAndAddress($instance) { $cui = $instance->cui; // remove the RO from cui, because this idiot api call won`t recognize it if( Str::contains($cui, ['ro', 'RO', 'Ro']) ){ $replace = [ 'RO'=>'', 'ro'=>'', 'RO'=>'', 'Ro'=>'', ]; $cui = strtr( $cui, $replace ); } // get from https://termene.ro/documentatie-api some company informations $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://termene.ro/api/dateFirmaSumar.php?cui='.$cui, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERPWD => env('TERMENE_USER').':'.env('TERMENE_PASSWORD'), CURLOPT_HTTPHEADER => array( "accept: */*", "content-type: application/json", ), )); $response = curl_exec($curl); curl_close($curl); // get an array of cUrl response $response = json_decode($response, true); if(isset($response['info_companie'])){ $infoCompany = $response['info_companie']; $adresa = $infoCompany['adresa_anaf']; if($adresa){ $replace = [ 'Ş'=>'S', 'Ț'=>'T', 'Ă'=>'A', 'Â'=>'A', ]; $adresa = strtr( $adresa, $replace ); } $instance->update([ 'reg_no' => $infoCompany['j'] ?? null, 'address' => $adresa ?? null, ]); return true; }else{ Log::critical("Nu am gasit date financiare pentru CUI-ul:".$cui); return false; } }
Back