Page achat de monnaie

This commit is contained in:
Matt Marcha 2018-11-08 11:30:28 +01:00
parent 96cf776642
commit d93e9dfabf
3 changed files with 89 additions and 16 deletions

View file

@ -23,7 +23,7 @@
<ion-item>
<ion-label stacked>N° de carte</ion-label>
<ion-input type="number"></ion-input>
<ion-input [(ngModel)]="cardnumber" name="cardnumber" type="number" min="0000000000000000" max="9999999999999999"></ion-input>
</ion-item>
<ion-item>
@ -31,17 +31,36 @@
<ion-input type="text"></ion-input>
</ion-item>
<ion-item>
<ion-label stacked>Date d'expiration</ion-label>
<ion-input type="number"></ion-input>
</ion-item>
<ion-grid>
<ion-row class="cb-date">
<ion-col col-5>
<ion-item>
<ion-label stacked>Date d'expiration</ion-label>
<ion-input [(ngModel)]="mounth" name="mounth" type="number" min="1" max="12"></ion-input>
</ion-item>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-2> / </ion-col>
</ion-row>
<ion-row>
<ion-col col-5>
<ion-item>
<ion-input [(ngModel)]="year" name="year" type="number"></ion-input>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
<ion-item>
<ion-label stacked>Cryptogramme</ion-label>
<ion-input type="number"></ion-input>
<ion-input [(ngModel)]="cryp" name="cryp" type="number" min="000" max="999"></ion-input>
</ion-item>
<button ion-button (click)="sendTransaction(amount)">Payer {{amount}} €</button>
<button ion-button (click)="sendTransaction(cardnumber, mounth, year, cryp, amount)">Payer {{amount}} €</button>
</ion-list>

View file

@ -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;
}
}
}

View file

@ -8,9 +8,6 @@
<ion-navbar>
<ion-title>Mon compte</ion-title>
<ion-buttons>
<button ion-item (click)="closeConnexion()">Se déconnecter</button>
</ion-buttons>
</ion-navbar>
</ion-header>
@ -32,6 +29,7 @@
<button ion-item (click)="changePage('buy')">Acheter de la monnaie locale</button>
<button ion-item (click)="changePage('send')">Faire un virement</button>
<button ion-item (click)="changePage('history')">Historique des transactions</button>
<button ion-item (click)="closeConnexion()">Se déconnecter</button>
</ion-buttons>
</ion-content>