-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.php
More file actions
1469 lines (1154 loc) · 47.7 KB
/
Copy pathTransaction.php
File metadata and controls
1469 lines (1154 loc) · 47.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Created by PhpStorm.
* User: davidkazad
* Date: 23/11/2018
* Time: 13:26
*/
/*
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
*/
require_once 'engine.php';
require_once 'Mailer.php';
require_once 'SmsGateway.php';
R::setup('mysql:host=localhost;dbname=cp973977_maishapay-api', 'root', '');
//R::setup('mysql:host=localhost;dbname=cp973977_maishapay-api','cp973977','Landry@22');
//R::setup('mysql:host=localhost;dbname=cp973977_test-maishapay','cp973977','Landry@22');
class Transaction
{
private $header;
private $result;
private $telephone;
private $pin;
private $expediteur;
private $destinateur;
private $montant;
private $monnaie;
private $nom;
private $prenom;
private $ville;
private $adresse;
private $email;
private $devise;
private $code_secret;
private $date_cloture;
private $beneficiaire;
private $tel_agent;
private $mt;
private $code_pin;
private $subject;
private $body;
private $type_epargne;
private $localCurrency;
private $localAmount;
private $defaultAmount;
// payment process
private $client_api_key;
private $payment_amount;
private $payment_devise;
private $payment_description;
private $page_callback_success;
private $page_callback_failure;
private $page_callback_cancel;
private $logo_url;
private $payment_token;
//create_merchant
private $merchant_name;
private $merchant_phone;
private $project_name;
private $merchant_email;
private $project_type;
private $project_description;
private $project_logo;
private $project_redirect_url;
private $project_callback_url;
private function Encapsulate($field)
{
if (isset($_POST[$field])) {
return $this->format_text($_POST[$field]);
} else {
//echo $_POST[$field];
echo json_encode(array('resultat' => 0, 'message' => 'Maishapay Encapsulation Fields Error! : ' . $field . ' not found exception'));
exit(0);
}
}
/**
* @return mixed
*/
public function getTelephone()
{
return $this->telephone = $this->Encapsulate('telephone');
}
/**
* @return mixed
*/
public function getPin()
{
return $this->pin = $this->Encapsulate('pin');
}
/**
* @return mixed
*/
public function getExpediteur()
{
return $this->expediteur = $this->Encapsulate('expeditaire');
}
/**
* @return mixed
*/
public function getDestinateur()
{
return $this->destinateur = $this->Encapsulate('destinataire');
}
/**
* @return mixed
*/
public function getMontant()
{
return $this->montant = $this->Encapsulate('montant');
}
/**
* @return mixed
*/
public function getMonnaie()
{
return $this->monnaie = $this->Encapsulate('monnaie');
}
/**
* @return mixed
*/
public function getNom()
{
return $this->nom = $this->Encapsulate('nom');
}
/**
* @return mixed
*/
public function getPrenom()
{
return $this->prenom = $this->Encapsulate('prenom');
}
/**
* @return mixed
*/
public function getVille()
{
return $this->ville = $this->Encapsulate('ville');
}
/**
* @return mixed
*/
public function getAdresse()
{
return $this->adresse = $this->Encapsulate('adresse');
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email = $this->Encapsulate('email');
}
/**
* @return mixed
*/
public function getCodeSecret()
{
return $this->code_secret = $this->Encapsulate('code_secret');
}
/**
* @return mixed
*/
public function getDevise()
{
return $this->devise = $this->Encapsulate('devise');
}
/**
* @return mixed
*/
public function getDateCloture()
{
return $this->date_cloture = $this->Encapsulate('date_cloture');
}
/**
* @return mixed
*/
public function getBeneficiaire()
{
return $this->beneficiaire = $this->Encapsulate('beneficiaire');
}
/**
* @return mixed
*/
public function getTelAgent()
{
return $this->tel_agent = $this->Encapsulate('tel_agent');
}
/**
* @return mixed
*/
public function getMt()
{
return $this->mt = $this->Encapsulate('mt');
}
/**
* @return mixed
*/
public function getCodePin()
{
return $this->code_pin = $this->Encapsulate('code_pin');
}
/**
* @return mixed
*/
public function getLocalCurrency()
{
return $this->localCurrency = $this->Encapsulate('local_currency');
}
/**
* @return mixed
*/
public function getLocalAmount()
{
return $this->localAmount = $this->Encapsulate('local_amount');
}
/**
* @return mixed
*/
public function getDefaultAmount()
{
return $this->defaultAmount = $this->Encapsulate('default_amount');
}
/**
* @return mixed
*/
public function getSubject()
{
return $this->subject = $this->Encapsulate('subject');
}
/**
* @return mixed
*/
public function getBody()
{
return $this->body = $this->Encapsulate('body');
}
/**
* @return mixed
*/
public function getClientApiKey()
{
return $this->client_api_key = $this->Encapsulate('client_api_key');
}
/**
* @return mixed
*/
public function getPaymentAmount()
{
return $this->payment_amount = $this->Encapsulate('payment_amount');
}
/**
* @return mixed
*/
public function getPaymentDevise()
{
return $this->payment_devise = $this->Encapsulate('payment_devise');
}
/**
* @return mixed
*/
public function getPaymentDescription()
{
return $this->payment_description = $this->Encapsulate('payment_description');
}
/**
* @return mixed
*/
public function getPageCallbackSuccess()
{
return $this->page_callback_success = $this->Encapsulate('page_callback_success');
}
/**
* @return mixed
*/
public function getPageCallbackFailure()
{
return $this->page_callback_failure = $this->Encapsulate('page_callback_failure');
}
/**
* @return mixed
*/
public function getPageCallbackCancel()
{
return $this->page_callback_cancel = $this->Encapsulate('page_callback_cancel');
}
/**
* @return mixed
*/
public function getLogoUrl()
{
return $this->logo_url = $this->Encapsulate('logo_url');
}
/**
* @return mixed
*/
public function getPaymentToken()
{
return $this->payment_token = $this->Encapsulate('token');
}
/**
* @return mixed
*/
public function getName()
{
return $this->name = $this->Encapsulate('name');
}
/**
* @return mixed
*/
public function getProjectName()
{
return $this->project_name = $this->Encapsulate('project_name');
}
/**
* @return mixed
*/
public function getMerchantEmail()
{
return $this->merchant_email = $this->Encapsulate('merchant_email');
}
/**
* @return mixed
*/
public function getProjectType()
{
return $this->project_type = $this->Encapsulate('project_type');
}
/**
* @return mixed
*/
public function getProjectDescription()
{
return $this->project_description = $this->Encapsulate('project_description');
}
/**
* @return mixed
*/
public function getProjectLogo()
{
return $this->project_logo = $this->Encapsulate('project_logo');
}
/**
* @return mixed
*/
public function getProjectRedirectUrl()
{
return $this->project_redirect_url = $this->Encapsulate('project_redirect_url');
}
/**
* @return mixed
*/
public function getProjectCallbackUrl()
{
return $this->project_callback_url = $this->Encapsulate('project_callback_url');
}
/**
* @return mixed
*/
public function getMerchantName()
{
return $this->merchant_name = $this->Encapsulate('merchant_name');
}
/**
* @return mixed
*/
public function getMerchantPhone()
{
return $this->merchant_phone = $this->Encapsulate('merchant_phone');
}
/**
* @return mixed
*/
public function getTypeEpargne()
{
return $this->type_epargne= $this->Encapsulate('type_epargne');
}
private function format_text($text)
{
return htmlentities(utf8_decode(htmlspecialchars($text)));
}
/**
* Transaction constructor.
* @param string $header
*/
public function __construct($header = '')
{
$this->header = $this->Encapsulate('ent');
$this->result = array('resultat' => 0, 'message' => 'Maishapay warning: data not found exception');
switch ($this->header) {
case 'solde' :
$this->solde($this->getTelephone());
$this->result();
break;
case 'solde_epargne_perso' :
$this->solde_epargne_perso($this->getTelephone());
$this->result();
break;
case 'profil':
$this->profile($this->getTelephone());
$this->result();
break;
case 'login':
$this->login($this->getTelephone(), $this->getPin());
$this->result();
break;
case 'inscription':
$this->insccription($this->getTelephone(), $this->getNom(), $this->getPrenom(), $this->getEmail(), $this->getAdresse(), $this->getVille(), $this->getCodePin());
$this->result();
break;
case 'creation_compte_epargne':
$this->creation_compte_epargne($this->getTelephone(), $this->getDevise(), $this->getLocalCurrency(), $this->getDateCloture(), $this->getLocalAmount(), $this->getDefaultAmount(), $this->getCodeSecret());
$this->result();
break;
case 'depot_epargne':
$this->depot_epargne($this->getTelephone(), $this->getMontant(), $this->getDevise(), $this->getDateCloture());
$this->result();
break;
case 'creation_compte_epargne_perso':
$this->creation_compte_epargne_perso($this->getTelephone(), $this->getDevise(), $this->getDateCloture(), $this->getCodeSecret());
$this->result();
break;
case 'creation_compte_epargne_avenir':
$this->creation_compte_avenir($this->getTelephone(), $this->getDevise(), $this->getDateCloture(), $this->getBeneficiaire(), $this->getCodeSecret());
$this->result();
break;
case 'transfert-compte':
$this->transfert_compte($this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie());
$this->result();
break;
case 'transfert-compte-confirmation':
$this->transfert_compte_confirmation($this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie(), $this->getPin());
$this->result();
break;
case 'retrait':
$this->transfert_compte($this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie());
$this->result();
break;
case 'confirmation-retrait':
$this->transfert_compte_confirmation($this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie(), $this->getPin());
$this->result();
break;
case 'rapport':
$this->rapport($this->getTelephone());
$this->result();
break;
case 'upd_profil':
$this->update_profile($this->getTelephone(), $this->getNom(), $this->getPrenom(), $this->getEmail(), $this->getAdresse(), $this->getVille(), $this->getPin());
$this->result();
break;
case 'taux':
$this->taux();
$this->result();
return;
break;
case 'conversion_monnaie':
$this->conversion($this->getMontant(), $this->getMonnaie());
$this->result();
break;
case 'nous_contacter':
$this->contact($this->getSubject(), $this->getBody(), $this->getEmail());
$this->result();
break;
case 'pin_perdu':
$this->pin_perdu($this->getTelephone(), $this->getEmail());
$this->result();
break;
case 'request_payment':
$this->request_payment($this->getClientApiKey(), $this->getPaymentAmount(), $this->getPaymentDevise());
$this->result();
break;
case 'web_request_payment':
$this->request_payment($this->getClientApiKey(), $this->getPaymentAmount(), $this->getPaymentDevise());
//$this->result();
break;
case 'request_completed':
$this->request_completed($this->getClientApiKey(), $this->getPaymentToken());
$this->result();
break;
case 'attempt_payment':
$this->attempt_payment($this->getClientApiKey(), $this->getPaymentToken());
$this->result();
break;
case 'confirm_payment':
$this->confirm_payment($this->getClientApiKey(), $this->getPaymentToken(), $this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie(), $this->getPin());
$this->result();
break;
case 'web_attempt_payment':
$this->attempt_payment($this->getClientApiKey(), $this->getPaymentToken());
$this->result();
break;
case 'web_confirm_payment':
$this->confirm_payment($this->getClientApiKey(), $this->getPaymentToken(), $this->getExpediteur(), $this->getDestinateur(), $this->getMontant(), $this->getMonnaie(), $this->getPin());
$this->result();
break;
case 'create_project':
$this->create_project($this->getMerchantName(), $this->getMerchantPhone(), $this->getMerchantEmail(), $this->getProjectName(), $this->getProjectType(), $this->getProjectDescription(), $this->getProjectLogo(), $this->getProjectRedirectUrl(), $this->getProjectCallbackUrl());
break;
case 'create_merchant':
$this->create_merchant($this->getTelephone(), $this->getNom(), $this->getPrenom(), $this->getEmail(), $this->getAdresse(), $this->getVille(), $this->getCodePin());
$this->result();
break;
case 'confirmation_transfert_epargne':
$this->confirmation_transfert_epargne($this->getTelephone(), $this->getTypeEpargne(), $this->getMontant(),$this->getMonnaie(),'');
$this->result();
break;
case 'transfert_epargne':
$this->transfert_epargne($this->getTelephone(), $this->getTypeEpargne(), $this->getMontant(),$this->getMonnaie());
$this->result();
break;
case 'message':
$test = false;
new SmsGateway('android-client', $test);
break;
case 'depot':
$this->depot($this->getTelephone(), $this->getMontant(),$this->getMonnaie());
$this->result();
break;
default :
$this->result;
}
}
public function result()
{
return $this->result;
}
public function data()
{
return $this->result;
}
public function jsonData()
{
return json_encode($this->result);
}
public function stringData()
{
echo json_encode($this->result);
}
public function solde($telephone)
{
$solde = R::findOne('solde', 'telephone=?', [$telephone]);
$this->result = array('resultat' => 0, 'Ce numero n\'exist pas');
if ($solde) {
$this->result = array('resultat' => 1, "FC" => $solde['fc'], "USD" => $solde['usd']);
}
return $this->result;
}
public function solde_epargne_perso($telephone)
{
$epargne = R::findOne('epargne1', 'telephone=?', [$telephone]);
$this->result = array('resultat' => 0);
if ($epargne)
$this->result = array("resultat" => 1, "FC" => $epargne['fc'], "USD" => $epargne['usd'], "end_date" => $epargne['end_date']);
return $this->result;
}
public function profile($telephone)
{
$profile = R::findOne('user', 'telephone=?', [$telephone]);
$this->result = array('nbresultat' => 0);
if ($profile) {
$this->result = array("nbresultat" => 1, "nom" => $profile['name'], "prenom" => $profile['firstname'], "email" => $profile['email'], "adresse" => $profile['adresse'], "ville" => $profile['ville']);
}
return $this->result;
// profile
/**/
}
public function login($telephone, $pin)
{
$user = R::findOne('user', 'telephone=?', [$telephone]);
if ($user)
if (password_verify($pin, $user['password']))
return $this->result = array("resultat" => 1, "nom" => $user['name'], "prenom" => $user['firstname'], "telephone" => $user['telephone'], "email" => $user['email'], "adresse" => $user['adresse'], "ville" => $user['ville']);
return $this->result = array('resultat' => 0, 'message' => "Nom d'utilisateur ou mot de passe incorrecte");
}
public function insccription($telephone, $nom, $prenom, $email, $adresse, $ville, $password, $usertype = 'A')
{
$this->result = array('resultat' => 0);
if ($this->checkTelephone($telephone))
return $this->result = array('resultat' => 2, 'message' => 'Numero de telephone déjà utiliser');
if ($this->checkEmail($email))
return $this->result = array('resultat' => 3, 'message' => 'Addresse email déjà utiliser');
$user = R::dispense('user');
$user->current_date = new DateTime();
$user->name = $nom;
$user->firstname = $prenom;
$user->telephone = $telephone;
$user->email = $email;
$user->adresse = $adresse;
$user->ville = $ville;
$user->password = password_hash($password, PASSWORD_DEFAULT);
$user->usertype = $usertype;
$user->status = 'A';
$id = R::store($user);
if ($id) {
$solde = R::dispense('solde');
$solde->telephone = $telephone;
$solde->usd = 0;
$solde->fc = 500;
R::store($solde);
//to be deleted
$journal = R::dispense('journal');
$journal->expediteur = '2223';
$journal->destinateur = $telephone;
$journal->montant = 500;
$journal->monnaie = 'FC';
$journal->type_journal = 1;
$journal->status = 'C';
R::store($journal);
return $this->result = array("resultat" => 1, "nom" => $nom, "prenom" => $prenom, "ville" => $ville, "telephone" => $telephone, 'message' => 'inscription effectueée avec succès!');
}
return $this->result;
}
private function checkEmail($email, $type = 'user')
{
return $user = R::count($type, 'email=?', [$email]);
}
private function checkTelephone($telephone, $type = 'user')
{
return $user = R::count($type, 'telephone=?', [$telephone]);
}
private function checkUser($telephone)
{
$this->result = R::findOne('user', 'telephone=?', [$telephone]);
if ($this->result) {
$this->result['resultat'] = 1;
return $this->result;
} else
return $this->result = array('resultat' => 0, 'message' => 'User not found');
}
private function checkMerchant($telephone)
{
$this->result = $this->checkUser($telephone);
if ($this->result['resultat'] == 1) {
if ($this->result['usertype'] != 'merchant')
$this->result['resultat'] = 2;
}
return $this->result;
}
public function checkSolde($telephone, $montant, $monnaie)
{
if ($monnaie == 'FC')
return $this->result = R::count('solde', 'telephone=? AND fc > ?', [$telephone, $montant + $this->maishapay_commission($montant, 'FC')]);
else if ($monnaie == 'USD')
return $this->result = R::count('solde', 'telephone=? AND usd > ?', [$telephone, $montant + $this->maishapay_commission($montant, 'USD')]);
}
public function creation_compte_epargne_perso($telephone, $devise, $end_date, $code_secret)
{
if ($this->checkTelephone($telephone, 'epargne1'))
//return $this->result = array('resultat' => 0, 'message' => 'Vous avez déjà un compte epargne personnel');
return $this->result = 0;
$epargne = R::dispense('epargne1');
$epargne->telephone = $telephone;
$epargne->password = sha1($code_secret);
$epargne->end_date = $end_date;
$epargne->usd = 0.0;
$epargne->fc = 0.0;
$epargne->status = 'A';
if (R::store($epargne)) {
return $this->result = 1;
}
return $this->result = 0;
}
public function creation_compte_avenir($telephone, $devise, $end_date, $beneficiaire, $code_secret)
{
if ($this->checkTelephone($telephone, 'epargne2'))
//return $this->result = array('resultat' => 0, 'message' => 'Vous avez déjà un compte epargne avenir');
return $this->result = 0;
$epargne = R::dispense('epargne2');
$epargne->telephone = $telephone;
$epargne->password = $code_secret;
$epargne->end_date = $end_date;
$epargne->usd = 0.0;
$epargne->fc = 0.0;
$epargne->status = 'A';
if (R::store($epargne))
return $this->result = 1;
return $this->result = 0;
}
public function transfert_compte($expediteur, $destinateur, $montant, $monnaie)
{
//if ($destinateur == $expediteur)
//return $this->result = array('resultat' => 0, 'message' => 'Vous ne pouvez pas transferer l\'argent a vous meme');
if ($user = $this->checkUser($destinateur)) {
if (!$this->checkTelephone($expediteur))
return $this->result = array('resultat' => 0, 'message' => "Numero de l' expediteur non trouvé");
if (!$this->checkTelephone($destinateur))
return $this->result = array('resultat' => 0, 'message' => "Numero de destinateur non trouvé");
if ($this->checkSolde($expediteur, $montant, $monnaie))
return $this->result = array("resultat" => 1, "nom" => $user['name'], "prenom" => $user['firstname'], 'message' => 'Vous etes sur le point de transferer ' . $montant . ' ' . $monnaie . ' à ' . $user['firstname'] . ' ' . $user['name']);
else
return $this->result = array("resultat" => 2, 'message' => 'solde insufissant');
} else {
return $this->result = array('resultat' => 0, 'message' => 'Numero du destinateur non trouvé');
}
}
private function maishapay_commission($montant, $monnaie)
{
if ($monnaie == 'USD') {
if ($montant >= 10) {
return 1.00;
} else {
return 0.500;
}
} else if ($monnaie == 'FC') {
if ($montant >= 10000) {
return 1000;
} else {
return 500;
}
}
}
public function transfert_compte_confirmation($expediteur, $destinateur, $montant, $monnaie, $pin)
{
if ($this->login($expediteur, $pin)['resultat'] == 1) {
if ($monnaie == 'USD')
$this->updateSoldeUSD($destinateur, $expediteur, $montant);
else if ($monnaie == 'FC')
$this->updateSoldeFC($destinateur, $expediteur, $montant);
}
return $this->result;
}
private function updateSoldeUSD($destinateur, $expediteur, $montant)
{
if ($this->transfert_compte($expediteur, $destinateur, $montant, 'USD')['resultat'] == 1) {
$solde_expediteur = R::findOne('solde', 'telephone=?', [$expediteur]);
$solde_destinateur = R::findOne('solde', 'telephone=?', [$destinateur]);
$updateSoldeExpediteur = R::load('solde', $solde_expediteur->getID());
$updateSoldeExpediteur->usd = $solde_expediteur['usd'] - $montant - $this->maishapay_commission($montant, 'USD'); // - commission
// update solde
$updateSoldeDestinateur = R::load('solde', $solde_destinateur->getID());
$updateSoldeDestinateur->usd = $solde_destinateur['usd'] + $montant;
if (R::store($updateSoldeExpediteur))
if (R::store($updateSoldeDestinateur)) {
// journalisation
$this->journalisation($expediteur, $destinateur, $montant, 'USD');
return $this->result = array('resultat' => 1, 'message' => 'transfert effectue avec success');
}
return $this->result = array('resultat' => 2, 'message' => 'Oparation failed');
}
}
private function updateSoldeFC($destinateur, $expediteur, $montant)
{
if ($this->transfert_compte($expediteur, $destinateur, $montant, 'FC')['resultat'] == 1) {
$solde_expediteur = R::findOne('solde', 'telephone=?', [$expediteur]);
$solde_destinateur = R::findOne('solde', 'telephone=?', [$destinateur]);
$updateSoldeExpediteur = R::load('solde', $solde_expediteur->getID());
$updateSoldeExpediteur->fc = $solde_expediteur['fc'] - $montant - $this->maishapay_commission($montant, 'FC'); // - commission
// update solde fc
$updateSoldeDestinateur = R::load('solde', $solde_destinateur->getID());
$updateSoldeDestinateur->fc = $solde_destinateur['fc'] + $montant;
if (R::store($updateSoldeExpediteur))
if (R::store($updateSoldeDestinateur)) {
$this->journalisation($expediteur, $destinateur, $montant, 'FC');
return $this->result = array('resultat' => 1, 'message' => 'transfert effectue avec success');
}
return $this->result = array('resultat' => 2, 'message' => 'Oparation failed');
}
}
private function journalisation($expediteur, $destinateur, $montant, $monnaie)
{
$journal = R::dispense('journal');
$journal->expediteur = $expediteur;
$journal->destinateur = $destinateur;
$journal->montant = $montant;
$journal->monnaie = $monnaie;
$journal->type_journal = 1;
$journal->status = 'C';
$cout = R::dispense('couttransaction');
$cout->montant = $this->maishapay_commission($montant, $monnaie);
$cout->monnaie = $monnaie;
$cout->current_date = new DateTime();
$cout[] = $journal;
R::store($cout);
}
public function taux()
{
if ($taux = R::findOne('taux'))
return $this->result = $taux['usd'];
return $this->result = 0;
}
public function conversion($montant, $monnaie)
{
if ($monnaie == "USD") {
$this->result = number_format(($montant * $this->taux()), 5, ".", " ") . " CDF";
} else {
$this->result = number_format(($montant / $this->taux()), 6, ".", " ") . " USD";
}
return $this->result;
}
public function update_profile($telephone, $nom, $prenom, $email, $adresse, $ville, $pin)
{
$user = R::findOne('user', 'telephone=?', [$telephone]);
if ($user) {
if (!password_verify($pin, $user['password']))
return $this->result = 2;
if ($this->checkEmail($email))
return $this->result = 3;
$updateUser = R::load('user', $user->getID());
$updateUser->name = $nom;
$updateUser->firstname = $prenom;
$updateUser->email = $email;
$updateUser->adresse = $adresse;
$updateUser->ville = $ville;
if (R::store($updateUser)) {
return $this->result = 1;
} else {
return $this->result = 0;
}
}
return $this->result = 4;
}
public function rapport($telephone)