src/app/studiopro/pro-upgrade.ts
Compbaser
selector | pro-upgrade |
styles |
input.ng-invalid {
border-right: 10px solid red;
}
.material-switch {
position: relative;
padding-top: 10px;
}
.input-group {
padding-top: 10px;
}
i {
width: 20px;
}
|
templateUrl | ./pro-upgrades.html |
constructor(fb: FormBuilder, yp: YellowPepperService, rp: RedPepperService)
|
Defined in src/app/studiopro/pro-upgrade.ts:34
|
Protected showMessage |
showMessage(i_title: string, i_msg: string, i_status: boolean)
|
Defined in src/app/studiopro/pro-upgrade.ts:51
|
Returns :
void
|
_detectCardType |
_detectCardType(number: any)
|
Defined in src/app/studiopro/pro-upgrade.ts:68
|
Returns :
void
|
_onStartSubscription |
_onStartSubscription()
|
Defined in src/app/studiopro/pro-upgrade.ts:109
|
Returns :
void
|
destroy |
destroy()
|
Defined in src/app/studiopro/pro-upgrade.ts:187
|
Returns :
void
|
formInputs |
formInputs: |
Defined in src/app/studiopro/pro-upgrade.ts:33
|
m_contGroup |
m_contGroup: |
Defined in src/app/studiopro/pro-upgrade.ts:34
|
import {Component} from "@angular/core";
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {Compbaser} from "ng-mslib";
import {YellowPepperService} from "../../services/yellowpepper.service";
import {RedPepperService} from "../../services/redpepper.service";
import {NGValidators} from "ng-validators";
import {equalValueValidator} from "../../Lib";
@Component({
selector: 'pro-upgrade',
templateUrl: './pro-upgrades.html',
styles: [`
input.ng-invalid {
border-right: 10px solid red;
}
.material-switch {
position: relative;
padding-top: 10px;
}
.input-group {
padding-top: 10px;
}
i {
width: 20px;
}
`]
})
export class ProUpgrade extends Compbaser {
formInputs = {};
m_contGroup: FormGroup;
constructor(private fb: FormBuilder, private yp: YellowPepperService, private rp: RedPepperService) {
super();
this.m_contGroup = this.fb.group({
'userName': ['', [Validators.required]],
'creditCard': ['', [NGValidators.isCreditCard()]],
'month': ['', [NGValidators.isNumeric()]],
'year': ['', [NGValidators.isNumeric()]],
'cv': ['', [NGValidators.isNumeric()]],
'password': ['', [Validators.required, Validators.minLength(3)]],
'confirmPassword': ['', [Validators.required, Validators.minLength(3)]]
},
{validator: equalValueValidator('password', 'confirmPassword')}
);
}
private showMessage(i_title: string, i_msg: string, i_status: boolean): void {
bootbox.hideAll();
bootbox.dialog({
closeButton: true,
title: i_title,
message: `<br/><br/><br/>
<center>
${i_status == true ? '<i style="color: green; font-size: 6em; padding:30px" class="fa fa-thumbs-up"></i>' : '<i style="color: red; font-size: 4em; padding: 30px" class="fa fa-thumbs-down"></i>'}
<h4>${i_msg}</h4>
<br/><br/><br/>
</center>`
});
}
_detectCardType(number) {
var re = {
electron: /^(4026|417500|4405|4508|4844|4913|4917)\d+$/,
maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/,
dankort: /^(5019)\d+$/,
interpayment: /^(636)\d+$/,
unionpay: /^(62|88)\d+$/,
visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
mastercard: /^5[1-5][0-9]{14}$/,
amex: /^3[47][0-9]{13}$/,
diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
jcb: /^(?:2131|1800|35\d{3})\d{11}$/
};
if (re.electron.test(number)) {
return 'ELECTRON';
} else if (re.maestro.test(number)) {
return 'MAESTRO';
} else if (re.dankort.test(number)) {
return 'DANKORT';
} else if (re.interpayment.test(number)) {
return 'INTERPAYMENT';
} else if (re.unionpay.test(number)) {
return 'UNIONPAY';
} else if (re.visa.test(number)) {
return 'VISA';
} else if (re.mastercard.test(number)) {
return 'MASTERCARD';
} else if (re.amex.test(number)) {
return 'AMEX';
} else if (re.diners.test(number)) {
return 'DINERS';
} else if (re.discover.test(number)) {
return 'DISCOVER';
} else if (re.jcb.test(number)) {
return 'JCB';
} else {
return undefined;
}
}
_onStartSubscription() {
if (this.m_contGroup.status != 'VALID')
return bootbox.alert('Please fix the fields marked in red');
const cardType = this._detectCardType(this.m_contGroup.controls.creditCard.value);
const userName = this.rp.getUserData().userName;
const userPass = this.rp.getUserData().userPass;
const year = this.m_contGroup.controls.year.value.length == 2 ? '20' + this.m_contGroup.controls.year.value : this.m_contGroup.controls.year.value;
const month = this.m_contGroup.controls.month.value.replace(/^0+/, '');
var card;
switch (cardType) {
case 'VISA': {
card = '0';
break;
}
case 'MASTERCARD': {
card = '1';
break;
}
case 'DISCOVER': {
card = '2';
break;
}
case 'AMEX': {
card = '3';
break;
}
default: {
card = '-1';
}
}
var url = `https://galaxy.signage.me/WebService/UpgradeToResellerAccount.ashx?userName=${userName}&userPassword=${userPass}&resellerUserName=${this.m_contGroup.controls.userName.value}&resellerPassword=${this.m_contGroup.controls.password.value}&cardType=${card}&cardNumber=${this.m_contGroup.controls.creditCard.value}&expirationMonth=${month}&expirationYear=${year}&securityCode=${this.m_contGroup.controls.cv.value}&callback=?`;
$.getJSON(url, (e) => {
var msg = '';
console.log('Credit card status ' + e.result);
switch (e.result) {
case -4: {
msg = 'This user is already under a subscription account';
this.showMessage(e.status, msg, false);
return;
}
case -5: {
msg = 'Enterprise use name is taken, please pick a different name';
this.showMessage(e.status, msg, false);
return;
}
case -3: {
}
case -2: {
}
case -1: {
msg = 'Problem with credit card, please use a different card';
this.showMessage(e.status, msg, false);
return;
}
default: {
if (e.result > 100) {
bootbox.hideAll();
$('.modal').modal('hide');
//var snippet = `Congratulations, be sure to checkout the <a href="http://www.digitalsignage.com/_html/video_tutorials.html?videoNumber=liteUpgrade" target="_blank">video tutorial</a> on how to install your newly available components from the mediaSTORE`;
var snippet = `Congratulations, be sure to go to the mediaSTORE and install your newly available components...`;
this.showMessage('success', snippet, true);
return;
} else {
msg = 'Problem with credit card, please use a different card';
this.showMessage(e.status, msg, false);
}
}
}
}).done((e) => {
}).fail((e) => {
this.showMessage(e.status, 'Could not complete, something went wrong on server side', false);
}).always(() => {
});
}
destroy() {
}
}
<form novalidate autocomplete="off" [formGroup]="m_contGroup">
<div class="row">
<div class="inner userGeneral">
<div class="panel-heading">
<small class="release">target properties
<i style="font-size: 1.4em" class="fa fa-cog pull-right"></i>
</small>
<small class="debug">{{me}}</small>
</div>
<a style="padding: 10px" i18n href="http://www.digitalsignage.com/_html/benefits.html" target="_blank">
Learn more about Enterprise
</a>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<img src="assets/accepted_c22e0.png">
</h3>
</div>
<div class="panel-body">
<form role="form" id="payment-form">
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label for="newName">Pick a new enterprise user name</label>
<div class="input-group">
<input id="newName" [formControl]="m_contGroup.controls['userName']" type="text" class="form-control" name="newName"/>
<span class="input-group-addon"><i class="fa fa-user-circle"></i></span>
</div>
</div>
<div class="form-group">
<label for="newPass">Pick an enterprise password</label>
<div class="input-group">
<input id="newPass" [formControl]="m_contGroup.controls['password']" id="upgPass" type="password" class="form-control" name="newPass"/>
<span class="input-group-addon"><i class="fa fa-key"></i></span>
</div>
</div>
<div class="form-group">
<label for="newPass2">Repeat your new password</label>
<div class="input-group">
<input id="newPass2" [formControl]="m_contGroup.controls['confirmPassword']" id="upgPass2" type="password" class="form-control" name="newPass2"/>
<span class="input-group-addon"><i class="fa fa-key"></i></span>
</div>
</div>
</div>
<div class="col-xs-12">
<div class="form-group">
<label for="cardNumber">CARD NUMBER</label>
<div class="input-group">
<input id="cardNumber" [formControl]="m_contGroup.controls['creditCard']" id="upgCredit" type="text" class="form-control" name="cardNumber" placeholder="Valid Card Number" required autofocus data-stripe="number"/>
<span class="input-group-addon"><i class="fa fa-credit-card"></i></span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-7 col-md-7">
<div class="form-group">
<div class="col-xs-6 col-lg-6 pl-ziro">
<input [formControl]="m_contGroup.controls['month']" type="text" class="form-control" name="expMonth" placeholder="MM" required data-stripe="exp_month"/>
</div>
<div class="col-xs-6 col-lg-6 pl-ziro">
<input [formControl]="m_contGroup.controls['year']" type="text" class="form-control" name="expYear" placeholder="YYYY" required data-stripe="exp_year"/>
</div>
</div>
</div>
<div class="col-xs-5 col-md-5 pull-right">
<div class="form-group">
<input [formControl]="m_contGroup.controls['cv']" class="form-control" name="cvCode" placeholder="CV" required data-stripe="cvc"/>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<button (click)="_onStartSubscription()" class="startUpgrade btn btn-success btn-lg btn-block" type="submit">Start Subscription</button>
</div>
</div>
<div class="row" style="display:none;">
<div class="col-xs-12">
<p class="payment-errors"></p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</form>