+ Update Receive payment from transmitter network method
This commit is contained in:
parent
a042f99199
commit
f9500c207b
|
@ -3,9 +3,12 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\ConfigWallet;
|
use App\Models\ConfigWallet;
|
||||||
use App\Models\TransmittedIlinkTransaction;
|
use App\Models\Network;
|
||||||
use App\Models\TransmittingNetwork;
|
use App\Models\TransmittingNetwork;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Wallet;
|
||||||
|
use App\Models\WalletAgent;
|
||||||
|
use App\Models\WalletIlinkTransaction;
|
||||||
use App\Models\WalletsUser;
|
use App\Models\WalletsUser;
|
||||||
use App\Traits\ApiResponser;
|
use App\Traits\ApiResponser;
|
||||||
use App\Traits\Helper;
|
use App\Traits\Helper;
|
||||||
|
@ -88,8 +91,9 @@ class TransmittingNetworksController extends Controller
|
||||||
public function receivePayment(Request $request)
|
public function receivePayment(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'type' => 'required|integer|in:1,3,17', // Les types de transactions possibles à recevoir [1,3,17]
|
'type' => 'required|integer|in:1,17', // Les types de transactions possibles à recevoir [1,3,17]
|
||||||
'montant' => 'required|numeric|min:0|not_in:0',
|
'montant' => 'required|numeric|min:0|not_in:0',
|
||||||
|
'montant_commission' => 'required|numeric|min:0|not_in:0',
|
||||||
'network_emetteur' => 'required|numeric|min:0|not_in:0',
|
'network_emetteur' => 'required|numeric|min:0|not_in:0',
|
||||||
'network_destinataire' => 'required|numeric|min:0|not_in:0',
|
'network_destinataire' => 'required|numeric|min:0|not_in:0',
|
||||||
'id_transaction_network_emetteur' => 'required',
|
'id_transaction_network_emetteur' => 'required',
|
||||||
|
@ -115,9 +119,21 @@ class TransmittingNetworksController extends Controller
|
||||||
return $this->errorResponse("Ce reseau n'est pas reconnu comme etant un reseau emetteur du reseau destinataire");
|
return $this->errorResponse("Ce reseau n'est pas reconnu comme etant un reseau emetteur du reseau destinataire");
|
||||||
|
|
||||||
|
|
||||||
$transaction = new TransmittedIlinkTransaction();
|
$transaction = new WalletIlinkTransaction();
|
||||||
$transaction->fill($request->all());
|
$transaction->fill($request->all());
|
||||||
$transaction->id_transaction = $this->getTransactionID();
|
$transaction->id_transaction = $this->getTransactionID();
|
||||||
|
$transaction->from_network_emetteur = true;
|
||||||
|
$transaction->frais = 0;
|
||||||
|
|
||||||
|
//Hyperviseur destinataire
|
||||||
|
$hyperviseurDestinataire = WalletAgent::where('category', 'hyper')->where('network_id', $request->network_destinataire)->firstOrFail();
|
||||||
|
$walletHyper = Wallet::findOrFail($hyperviseurDestinataire->wallet_id);
|
||||||
|
$transaction->id_wallet_hyp = $walletHyper->id;
|
||||||
|
$finalNetwork = Network::findOrFail($request->network_destinataire);
|
||||||
|
$transaction->final_country = $finalNetwork->country->id;
|
||||||
|
$initNetwork = Network::findOrFail($request->network_emetteur);
|
||||||
|
$transaction->init_country = $initNetwork->country->id;
|
||||||
|
$transaction->montant_net = $request->montant;
|
||||||
|
|
||||||
switch ($request->type) {
|
switch ($request->type) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -130,25 +146,40 @@ class TransmittingNetworksController extends Controller
|
||||||
'id_document_emetteur' => 'required',
|
'id_document_emetteur' => 'required',
|
||||||
'id_emetteur' => 'required',
|
'id_emetteur' => 'required',
|
||||||
]);
|
]);
|
||||||
$user = User::where('user_code', $request->id_destinataire)->firstOrFail();
|
|
||||||
$wallet_user = WalletsUser::where('idUser', $user->id)->firstOrFail();
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
||||||
// Verifier si le wallet destinataire appartient au meme pays que le reseau
|
if ($destinataire) { // Si c'est un wallet ilink
|
||||||
$wallet_user->balance += $request->montant;
|
if ($destinataire->network->country->id == $finalNetwork->country->id) {
|
||||||
$wallet_user->save();
|
$walletDestinataire = WalletsUser::where('idUser', $destinataire->id)->firstOrFail();
|
||||||
|
$walletDestinataire->balance += $request->montant;
|
||||||
|
$transaction->id_wallet_user = $walletDestinataire->id;
|
||||||
|
$walletDestinataire->save();
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(trans('errors.wallet_country_not_match', ['country' => $finalNetwork->country->name]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $this->errorResponse(trans('errors.wallet_not_defined'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$walletHyper->balance_com += $request->montant_commission;
|
||||||
|
$walletHyper->save();
|
||||||
|
|
||||||
$transmittingNetwork->balance_compensation += $request->montant;
|
$transmittingNetwork->balance_compensation += $request->montant;
|
||||||
|
$transmittingNetwork->balance_com += $request->montant_commission;
|
||||||
$transmittingNetwork->save();
|
$transmittingNetwork->save();
|
||||||
|
|
||||||
|
$transaction->commission_hyp = $request->montant_commission;
|
||||||
$transaction->save();
|
$transaction->save();
|
||||||
|
|
||||||
$message = trans('messages.wallet_incoming_payment_message',
|
$message = trans('messages.wallet_incoming_payment_message',
|
||||||
['amount' => $this->toMoneyWithNetwork($request->montant, $request->id), 'transmitter' => $request->nom_emetteur . ' ' . $request->prenom_emetteur]);
|
['amount' => $this->toMoneyWithNetwork($request->montant, $request->id), 'transmitter' => $request->nom_emetteur . ' ' . $request->prenom_emetteur]);
|
||||||
|
|
||||||
$this->sendMail($user->email, trans('messages.wallet_incoming_payment'), $message);
|
$this->sendMail($destinataire->email, trans('messages.wallet_incoming_payment'), $message);
|
||||||
return $this->successResponse(trans('messages.success_treated_demand'));
|
return $this->successResponse(trans('messages.success_treated_demand'));
|
||||||
break;
|
case 17:
|
||||||
case 2:
|
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
|
'id_emetteur' => 'required',
|
||||||
'nom_emetteur' => 'required',
|
'nom_emetteur' => 'required',
|
||||||
'prenom_emetteur' => 'required',
|
'prenom_emetteur' => 'required',
|
||||||
'type_document_emetteur' => 'required',
|
'type_document_emetteur' => 'required',
|
||||||
|
@ -157,10 +188,32 @@ class TransmittingNetworksController extends Controller
|
||||||
'nom_destinataire' => 'required',
|
'nom_destinataire' => 'required',
|
||||||
'prenom_destinataire' => 'required',
|
'prenom_destinataire' => 'required',
|
||||||
'type_document_destinataire' => 'required',
|
'type_document_destinataire' => 'required',
|
||||||
|
'id_document_destinataire' => 'required',
|
||||||
|
'email_destinataire' => 'required',
|
||||||
|
'code_retrait' => 'required'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$hash = $this->hashSSHA($request->code_retrait);
|
||||||
|
$transaction->encrypted_code_retrait = $hash['encrypted'];
|
||||||
|
$transaction->code_retrait_salt = $hash['salt'];
|
||||||
|
$transaction->status_retrait = false;
|
||||||
|
|
||||||
|
$transaction->commission_ag = floatval($request->montant_commission * $configRecipient->taux_com_ag_envoi_cash / 100);
|
||||||
|
$transaction->commission_sup = floatval($request->montant_commission * $configRecipient->taux_com_sup_envoi_cash / 100);
|
||||||
|
$transaction->commission_hyp = floatval($request->montant_commission * $configRecipient->taux_com_hyp_envoi_cash / 100);
|
||||||
|
|
||||||
|
$transaction->save();
|
||||||
|
|
||||||
|
$message = trans('messages.cash_incoming_payment_message',
|
||||||
|
['amount' => $this->toMoneyWithNetwork($request->montant, $request->id), 'id_transaction' => $transaction->id_transaction,
|
||||||
|
'sender_name' => $request->nom_emetteur . ' ' . $request->prenom_emetteur, 'receiver_name' => $request->nom_destinataire . ' ' . $request->prenom_destinataire,
|
||||||
|
'code' => wordwrap($request->code_retrait, 4, ' ', true), 'init_country' => $initNetwork->country->name,
|
||||||
|
'final_country' => $finalNetwork->country->name]);
|
||||||
|
|
||||||
|
$this->sendMail($request->email_destinataire, trans('messages.cash_incoming_payment'), $message);
|
||||||
return $this->successResponse(trans('messages.success_treated_demand'));
|
return $this->successResponse(trans('messages.success_treated_demand'));
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 18:
|
||||||
return $this->successResponse(trans('messages.success_treated_demand'));
|
return $this->successResponse(trans('messages.success_treated_demand'));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -170,7 +223,7 @@ class TransmittingNetworksController extends Controller
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
$code = $this->generateTransactionCode();
|
$code = $this->generateTransactionCode();
|
||||||
$result = collect(DB::select('SELECT * FROM transmitted_ilink_transaction WHERE id_transaction = :code', ['code' => $code]));
|
$result = collect(DB::select('SELECT * FROM wallet_ilink_transaction WHERE id_transaction = :code', ['code' => $code]));
|
||||||
$codeCorrect = sizeof($result) < 0;
|
$codeCorrect = sizeof($result) < 0;
|
||||||
} while ($codeCorrect);
|
} while ($codeCorrect);
|
||||||
return $code;
|
return $code;
|
||||||
|
|
|
@ -1150,6 +1150,7 @@ class iLinkTransactionController extends Controller
|
||||||
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
$frais = ($init_country != $request->final_country) ? $this->calculateFees($plr_user_wallet_wallet, $request->montant) : $this->calculateFees($plr_user_wallet_wallet_national, $request->montant);
|
||||||
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
$taxe = ($init_country != $request->final_country) ? $this->calculateTax($taxesInternationales, $frais) : $this->calculateTax($taxesNationales, $frais);
|
||||||
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
$destinataire = User::where('user_code', $request->id_destinataire)->first();
|
||||||
|
//Verifier si c'est pas un reseau ilink
|
||||||
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire;
|
$data['destinataire'] = $destinataire ? $destinataire->lastname . ' ' . $destinataire->firstname : $request->id_destinataire;
|
||||||
$data['frais'] = round($frais + $taxe,2);
|
$data['frais'] = round($frais + $taxe,2);
|
||||||
$data['montant_net_init'] = round($request->montant - $data['frais'] , 2);
|
$data['montant_net_init'] = round($request->montant - $data['frais'] , 2);
|
||||||
|
|
|
@ -17,7 +17,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property int $network_destinataire
|
* @property int $network_destinataire
|
||||||
* @property int $network_emetteur
|
* @property int $network_emetteur
|
||||||
* @property float $montant
|
* @property float $montant
|
||||||
* @property int $id_destinataire
|
* @property float $montant_commission
|
||||||
|
* @property string $id_destinataire
|
||||||
* @property string|null $nom_destinataire
|
* @property string|null $nom_destinataire
|
||||||
* @property string|null $prenom_destinataire
|
* @property string|null $prenom_destinataire
|
||||||
* @property string|null $type_document_destinataire
|
* @property string|null $type_document_destinataire
|
||||||
|
@ -42,7 +43,7 @@ class TransmittedIlinkTransaction extends Model
|
||||||
'network_destinataire' => 'int',
|
'network_destinataire' => 'int',
|
||||||
'network_emetteur' => 'int',
|
'network_emetteur' => 'int',
|
||||||
'montant' => 'float',
|
'montant' => 'float',
|
||||||
'id_destinataire' => 'int',
|
'montant_commission' => 'float',
|
||||||
'type' => 'int'
|
'type' => 'int'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ class TransmittedIlinkTransaction extends Model
|
||||||
'network_destinataire',
|
'network_destinataire',
|
||||||
'network_emetteur',
|
'network_emetteur',
|
||||||
'montant',
|
'montant',
|
||||||
|
'montant_commission',
|
||||||
'id_destinataire',
|
'id_destinataire',
|
||||||
'nom_destinataire',
|
'nom_destinataire',
|
||||||
'prenom_destinataire',
|
'prenom_destinataire',
|
||||||
|
|
|
@ -18,14 +18,14 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property Carbon $created_date
|
* @property Carbon $created_date
|
||||||
* @property int $networks_agent_id
|
* @property int $networks_agent_id
|
||||||
* @property int $agent_id
|
* @property int $agent_id
|
||||||
* @property string $lastname
|
* @property string|null $lastname
|
||||||
* @property string $codeMembre
|
* @property string|null $codeMembre
|
||||||
* @property string $codeParrain
|
* @property string|null $codeParrain
|
||||||
* @property string $category
|
* @property string|null $category
|
||||||
* @property int $network_id
|
* @property int $network_id
|
||||||
* @property string $network
|
* @property string $network
|
||||||
* @property string $currency_code
|
* @property string|null $currency_code
|
||||||
* @property string $transactionNumber
|
* @property string|null $transactionNumber
|
||||||
*
|
*
|
||||||
* @package App\Models
|
* @package App\Models
|
||||||
*/
|
*/
|
||||||
|
@ -35,7 +35,7 @@ class WalletAgent extends Model
|
||||||
public $incrementing = false;
|
public $incrementing = false;
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'wallet_id' => 'int',
|
'wallet_id' => 'int',
|
||||||
'balance_princ' => 'float',
|
'balance_princ' => 'float',
|
||||||
'balance_com' => 'float',
|
'balance_com' => 'float',
|
||||||
|
@ -48,7 +48,7 @@ class WalletAgent extends Model
|
||||||
'created_date'
|
'created_date'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'wallet_id',
|
'wallet_id',
|
||||||
'balance_princ',
|
'balance_princ',
|
||||||
'balance_com',
|
'balance_com',
|
||||||
|
|
|
@ -58,6 +58,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property int $type
|
* @property int $type
|
||||||
* @property Carbon $date
|
* @property Carbon $date
|
||||||
* @property string pspReference
|
* @property string pspReference
|
||||||
|
* @property bool $from_network_emetteur
|
||||||
|
* @property string|null $id_transaction_network_emetteur
|
||||||
|
* @property float $montant_commission
|
||||||
*
|
*
|
||||||
* @property Country $country
|
* @property Country $country
|
||||||
* @property Wallet $wallet
|
* @property Wallet $wallet
|
||||||
|
@ -87,18 +90,20 @@ class WalletIlinkTransaction extends Model
|
||||||
'init_country' => 'int',
|
'init_country' => 'int',
|
||||||
'final_country' => 'int',
|
'final_country' => 'int',
|
||||||
'commission_banque' => 'float',
|
'commission_banque' => 'float',
|
||||||
'commission_ag' => 'float',
|
'commission_ag' => 'float',
|
||||||
'commission_sup' => 'float',
|
'commission_sup' => 'float',
|
||||||
'commission_hyp' => 'float',
|
'commission_hyp' => 'float',
|
||||||
'commission_hyp_final_country'=>'float',
|
'commission_hyp_final_country' => 'float',
|
||||||
'id_wallet_user' => 'int',
|
'id_wallet_user' => 'int',
|
||||||
'id_wallet_ag' => 'int',
|
'id_wallet_ag' => 'int',
|
||||||
'id_wallet_sup' => 'int',
|
'id_wallet_sup' => 'int',
|
||||||
'id_wallet_hyp' => 'int',
|
'id_wallet_hyp' => 'int',
|
||||||
'id_wallet_hyp_payeur' => 'int',
|
'id_wallet_hyp_payeur' => 'int',
|
||||||
'canceled' => 'int',
|
'canceled' => 'int',
|
||||||
'type' => 'int'
|
'type' => 'int',
|
||||||
];
|
'from_network_emetteur' => 'bool',
|
||||||
|
'montant_commission' => 'float'
|
||||||
|
];
|
||||||
|
|
||||||
protected $dates = [
|
protected $dates = [
|
||||||
'date_retrait',
|
'date_retrait',
|
||||||
|
@ -151,7 +156,10 @@ class WalletIlinkTransaction extends Model
|
||||||
'canceled',
|
'canceled',
|
||||||
'type',
|
'type',
|
||||||
'date',
|
'date',
|
||||||
'pspReference'
|
'pspReference',
|
||||||
|
'from_network_emetteur',
|
||||||
|
'id_transaction_network_emetteur',
|
||||||
|
'montant_commission'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function country()
|
public function country()
|
||||||
|
|
|
@ -396,7 +396,7 @@ trait Helper
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendFrame($paying_network_url, WalletIlinkTransaction $transaction)
|
public function sendFrame($paying_network_url, WalletIlinkTransaction $transaction, $code_retrait = null)
|
||||||
{
|
{
|
||||||
$client = new \GuzzleHttp\Client();
|
$client = new \GuzzleHttp\Client();
|
||||||
|
|
||||||
|
@ -427,6 +427,9 @@ trait Helper
|
||||||
$trame->type_document_destinataire = $transaction->type_document_destinataire;
|
$trame->type_document_destinataire = $transaction->type_document_destinataire;
|
||||||
$trame->id_document_destinataire = $transaction->id_document_destinataire;
|
$trame->id_document_destinataire = $transaction->id_document_destinataire;
|
||||||
$trame->montant = $transaction->montant_net_final_country;
|
$trame->montant = $transaction->montant_net_final_country;
|
||||||
|
$trame->montant_commission = $transaction->part_reseau_payeur_final_country;
|
||||||
|
if ($code_retrait)
|
||||||
|
$trame->code_retrait = $code_retrait;
|
||||||
$trame->currency = CountriesCurrency::findOrFail($transaction->final_country)->currency_code;
|
$trame->currency = CountriesCurrency::findOrFail($transaction->final_country)->currency_code;
|
||||||
|
|
||||||
return $client->request('POST', $paying_network_url, ['json' => $trame]);
|
return $client->request('POST', $paying_network_url, ['json' => $trame]);
|
||||||
|
|
|
@ -247,4 +247,16 @@ Savings Information :
|
||||||
"successful_password_update" => "Your password has been updated successfully.",
|
"successful_password_update" => "Your password has been updated successfully.",
|
||||||
"your_new_password" => "Your new password is: password.",
|
"your_new_password" => "Your new password is: password.",
|
||||||
"password_update" => "Update your password",
|
"password_update" => "Update your password",
|
||||||
|
"wallet_incoming_payment" => "Payment entering your wallet",
|
||||||
|
"wallet_incoming_payment_message" => "You have received a payment of :amount, coming from :transmitter",
|
||||||
|
"cash_incoming_payment" => "Incoming payment in cash.",
|
||||||
|
"cash_incoming_payment_message" => "You have received a cash payment.
|
||||||
|
Transaction Information:
|
||||||
|
- Transaction ID: :id_transaction
|
||||||
|
- Amount: :amount
|
||||||
|
- Country of departure: :init_country
|
||||||
|
- Name of the sender: :sender_name
|
||||||
|
- Country of destination: :final_country
|
||||||
|
- Recipient's names: :receiver_name
|
||||||
|
- Collection code: :code",
|
||||||
];
|
];
|
||||||
|
|
|
@ -251,4 +251,14 @@ Informations sur l'epargne :
|
||||||
"password_update" => "Mise à jour de votre mot de passe",
|
"password_update" => "Mise à jour de votre mot de passe",
|
||||||
"wallet_incoming_payment" => "Paiement entrant dans votre portefeuille",
|
"wallet_incoming_payment" => "Paiement entrant dans votre portefeuille",
|
||||||
"wallet_incoming_payment_message" => "Vous avez recu un paiement de :amount , venant de :transmitter",
|
"wallet_incoming_payment_message" => "Vous avez recu un paiement de :amount , venant de :transmitter",
|
||||||
|
"cash_incoming_payment" => "Paiement entrant en cash.",
|
||||||
|
"cash_incoming_payment_message" => "Vous avez recu un paiement en cash.
|
||||||
|
Informations de la transaction :
|
||||||
|
- Transaction ID : :id_transaction
|
||||||
|
- Montant : :amount
|
||||||
|
- Pays de départ : :init_country
|
||||||
|
- Noms de l'emetteur : :sender_name
|
||||||
|
- Pays de destination : :final_country
|
||||||
|
- Noms du destinataire : :receiver_name
|
||||||
|
- Code de retrait : :code",
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue