diff --git a/src/pages/buy/buy.html b/src/pages/buy/buy.html
index ab46543..a026b54 100644
--- a/src/pages/buy/buy.html
+++ b/src/pages/buy/buy.html
@@ -23,7 +23,7 @@
N° de carte
-
+
@@ -31,17 +31,36 @@
-
- Date d'expiration
-
-
+
+
+
+
+
+
+ Date d'expiration
+
+
+
+
+
+ /
+
+
+
+
+
+
+
+
+
+
Cryptogramme
-
+
-
+
diff --git a/src/pages/buy/buy.ts b/src/pages/buy/buy.ts
index 58b2b96..8cefda3 100644
--- a/src/pages/buy/buy.ts
+++ b/src/pages/buy/buy.ts
@@ -23,19 +23,75 @@ export class BuyPage {
console.log('ionViewDidLoad BuyPage');
}
- sendTransaction($amount) {
- //TODO : Contacter l'API et proposer la transaction. L'API répondra true ou False
- if (true === true) {
- this.navCtrl.popToRoot();
+ sendTransaction($cardnumber, $month, $year, $cryp, $amount) {
+ if (typeof $cardnumber !== 'undefined' && typeof $month !== 'undefined' && typeof $year !== 'undefined' && typeof $cryp !== 'undefined' && typeof $amount !== 'undefined' ) {
+ if (this.checkFields($cardnumber, $month, $year, $cryp)) {
+ //TODO : Contacter l'API et proposer la transaction. L'API répondra true ou False
+ if (true === true) {
+ this.navCtrl.popToRoot();
+ }
+ else {
+ const alert = this.alertCtrl.create({
+ title: 'Erreur',
+ subTitle: 'La transaction a échoué. Vérifiez les données saisies et réessayez.',
+ buttons: ['OK']
+ });
+ alert.present();
+ }
+ }
}
else {
const alert = this.alertCtrl.create({
- title: 'Erreur',
- subTitle: 'La transaction a échoué. Vérifiez les données saisies et réessayez.',
+ title: 'Champs vides',
+ subTitle: 'Merci de remplir tous les champs',
buttons: ['OK']
});
alert.present();
}
}
+ //Vérification des champs
+ checkFields(cardnumber, month, year, cryp) {
+ if (!this.checkCardInfoIntegrity(12, 19, cardnumber) || !this.checkCardInfoIntegrity(3, 4, cryp) || !this.checkCardInfoValue(0, 9999, cryp)) {
+ const alert = this.alertCtrl.create({
+ title: 'Erreur',
+ subTitle: 'Le numéro de carte bancaire est erroné. Vérifiez les données et recommencez.',
+ buttons: ['OK']
+ });
+ alert.present();
+ return false;
+ }
+ else if (!this.checkCardInfoIntegrity(1, 2, month) || !this.checkCardInfoValue(1, 12, month) || !this.checkCardInfoIntegrity(4, 4, year) || !this.checkCardInfoValue(2018, 2050, year)) {
+ const alert = this.alertCtrl.create({
+ title: 'Erreur',
+ subTitle: 'La date est erronée. Vérifiez les données et recommencez.',
+ buttons: ['OK']
+ });
+ alert.present();
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+ checkCardInfoIntegrity($min, $max, $number) {
+ $number = parseInt($number);
+ if ($number.length < $min || $number.length > $max) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+
+ checkCardInfoValue($min, $max, $number) {
+ $number = parseInt($number);
+ if ($number < $min || $number > $max) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
+
}
diff --git a/src/pages/home/home.html b/src/pages/home/home.html
index 977b105..775d37e 100644
--- a/src/pages/home/home.html
+++ b/src/pages/home/home.html
@@ -8,9 +8,6 @@
Mon compte
-
-
-
@@ -32,6 +29,7 @@
+