11declare const Cleave
22declare const StripeCheckout
3- const Stripe_publicKey = 'pk_test_uV27MTvcPM147KFo3HazbunU '
3+ const Stripe_publicKey = 'pk_live_VwEPmqkSAjDyjdia7xn4rAK9 '
44
55class coGateRegion {
66 public QTConnectData = ko . observable ( null )
@@ -452,10 +452,12 @@ class CoGateClass {
452452 self . showCards ( true )
453453 if ( payment ) {
454454 const uuuu = self . QTTransferData ( )
455- uuuu . totalMonth = payment . totalMonth
456- uuuu . productionPackage = payment . productionPackage
457- uuuu . expire = payment . expire
458- uuuu . paidAmount = payment . paidAmount
455+ uuuu . totalMonth = payment . totalMonth || uuuu . totalMonth
456+ uuuu . productionPackage = payment . productionPackage || uuuu . productionPackage
457+ uuuu . expire = payment . expire || uuuu . expire
458+ uuuu . paidAmount = payment . paidAmount || uuuu . paidAmount
459+
460+ uuuu . automatically = payment . paidAmount > 0 ? true : uuuu . automatically
459461 self . QTTransferData ( uuuu )
460462 }
461463 return self . CoGateAccount ( uu = null )
@@ -465,107 +467,13 @@ class CoGateClass {
465467
466468}
467469
468- interface PlanArray {
469- name : string
470- }
471-
472- const planArray = [
473- {
474- name :'free' ,
475- showName : [ '免费用户' , '無料ユーザー' , 'FREE USER' , '免費用戶' ] ,
476- monthlyPay : '0' ,
477- annually : '0' ,
478- annuallyMonth : '0' ,
479- next :'p1' ,
480- share : 0 ,
481- internet : 0 ,
482- tail : ko . observable ( false ) ,
483- multi_gateway :0 ,
484- showNote : false ,
485- showButton : ko . observable ( false ) ,
486- features : [ {
487- title : [ '代理区域' , 'エリア' , 'Region' , '代理區域' ] ,
488- detail : [ '巴黎' , 'パリ' , 'Paris' , '巴黎' ] ,
489- } , {
490- title : [ '服务器' , 'サーバー' , 'Server' , '伺服器' ] ,
491- detail : [ '共享' , '共有' , 'Share' , '共享' ] ,
492- } , {
493- title : [ '月流量限制' , '月データ制限' , 'Bandwidth' , '月流量限制' ] ,
494- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
495- } , {
496- title : [ '多代理' , 'マルチプロクシ' , 'Multi-Gateway' , '多代理' ] ,
497- detail : [ '1' , '1' , '1' , '1' ] ,
498- } , {
499- title : [ '客户端数' , '端末数' , 'Devices' , '客戶端數' ] ,
500- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
501- } ]
502-
503- } , {
504- name :'p1' ,
505- showName : [ '普通用户' , '普通ユーザー' , 'NORMAL USER' , '普通用戶' ] ,
506- monthlyPay : '5.88' ,
507- annually : '59.88' ,
508- annuallyMonth :'4.99' ,
509- next :'p2' ,
510- share : 0 ,
511- internet : 0 ,
512- tail : ko . observable ( false ) ,
513- multi_gateway :0 ,
514- showNote : false ,
515- showButton : ko . observable ( false ) ,
516- features : [ {
517- title : [ '代理区域' , 'エリア' , 'Region' , '代理區域' ] ,
518- detail : [ '全球16区域' , 'グローバル16区域' , '16 regions worldwide ' , '全球16區域' ] ,
519- } , {
520- title : [ '服务器' , 'サーバー' , 'Server' , '伺服器' ] ,
521- detail : [ '共享' , '共有' , 'Share' , '共享' ] ,
522- } , {
523- title : [ '月流量限制' , '月データ制限' , 'Bandwidth' , '月流量限制' ] ,
524- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
525- } , {
526- title : [ '多代理' , 'マルチプロクシ' , 'Multi-Gateway' , '多代理' ] ,
527- detail : [ '2' , '2' , '2' , '2' ] ,
528- } , {
529- title : [ '客户端数' , '端末数' , 'Devices' , '客戶端數' ] ,
530- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
531- } ]
532- } , {
533- name :'p2' ,
534- showName : [ '超级用户' , 'スーパーユーザー' , 'POWER USER' , '超級用戶' ] ,
535- monthlyPay : '19.88' ,
536- annually : '199.99' ,
537- annuallyMonth : '16.67' ,
538- share : 0 ,
539- internet : 0 ,
540- multi_gateway :0 ,
541- showNote : false ,
542- tail : ko . observable ( false ) ,
543- showButton : ko . observable ( false ) ,
544- features : [ {
545- title : [ '代理区域' , 'エリア' , 'Region' , '代理區域' ] ,
546- detail : [ '全球16区域' , 'グローバル16区域' , '16 regions worldwide ' , '全球16區域' ] ,
547- } , {
548- title : [ '服务器' , 'サーバー' , 'Server' , '伺服器' ] ,
549- detail : [ '独占' , '独占' , 'Dedicated' , '獨占' ] ,
550- } , {
551- title : [ '月流量限制' , '月データ制限' , 'Bandwidth' , '月流量限制' ] ,
552- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
553- } , {
554- title : [ '多代理' , 'マルチプロクシ' , 'Multi-Gateway' , '多代理' ] ,
555- detail : [ '4' , '4' , '4' , '4' ] ,
556- } , {
557- title : [ '客户端数' , '端末数' , 'Devices' , '客戶端數' ] ,
558- detail : [ '无限制' , '無制限' , 'Unlimited' , '無限制' ] ,
559- } ]
560- }
561- ]
562470
563471
564472class planUpgrade {
565473
566- public annually : string
567- public annuallyMonth : string
568- public totalAmount : KnockoutComputed < string >
474+ public annually : number
475+ public annuallyMonth : number
476+ public totalAmount = ko . observable ( 0 )
569477 public currentPromoIndex : number
570478
571479
@@ -580,10 +488,10 @@ class planUpgrade {
580488
581489
582490 //public annually = this.promo ? Math.round ( this.promoPrice * this.plan.annually * 100 )/100 : this.plan.annually
583- public planExpiration : string
491+
584492 public monthlyPay = this . plan . monthlyPay
585493 public showCancel = ko . observable ( false )
586- public showCurrentPlanBalance = null
494+ public CurrentPlanBalance = ko . observable ( - 1 )
587495 public cardNumberFolder_Error = ko . observable ( false )
588496 public cvcNumber_Error = ko . observable ( false )
589497 public postcode_Error = ko . observable ( false )
@@ -607,6 +515,7 @@ class planUpgrade {
607515 public paymentError = ko . observable ( false )
608516 public oldPlanUpgrade = ko . observable ( null )
609517 public paymentData = null
518+ public isAutomaticallyAgain = ko . observable ( false )
610519 private clearPaymentError ( ) {
611520 this . cardNumberFolder_Error ( false )
612521 this . cvcNumber_Error ( false )
@@ -627,44 +536,23 @@ class planUpgrade {
627536 this . currentPromo ( this . _promo )
628537 }
629538
630- this . annually = this . currentPromo ( ) ? ( Math . round ( parseInt ( this . plan . annually * 100 ) * this . currentPromo ( ) . pricePromo ) / 100 ) . toString ( ) : this . plan . annually
539+ this . annually = this . currentPromo ( ) ? Math . round ( this . plan . annually * this . currentPromo ( ) . pricePromo ) : this . plan . annually
631540 const month = this . currentPromo ( ) ? 12 * this . currentPromo ( ) . datePromo : 12
632- this . annuallyMonth = ( Math . round ( parseInt ( this . annually * 100 ) / month ) / 100 ) . toString ( )
633-
541+ this . annuallyMonth = Math . round ( this . annually / month )
542+ this . annually = this . annually
634543 this . currentPlan ( planArray [ planArray . findIndex ( function ( n ) {
635544 return n . name === self . dataTransfer . productionPackage
636545 } ) ] )
637-
546+
638547 if ( planNumber === 2 ) {
639548 this . showNote ( true )
640- if ( this . currentPlan ( ) . name === 'p1' ) {
641- const oldPlanUpgrade = {
642- oldPlanBalanceMonths : getRemainingMonth ( dataTransfer . expire ) ,
643- oldPlanMonthlyCost : dataTransfer . paidAmount * 100 / dataTransfer . totalMonth
644-
645- }
549+ if ( this . currentPlan ( ) . name === 'p1' && dataTransfer . isAnnual ) {
550+
646551 }
647552
648553 }
649554 this . samePlan ( this . currentPlan ( ) . name === planNumber )
650-
651-
652- this . showCurrentPlanBalance = ko . computed ( function ( ) {
653- if ( / f r e e / i. test ( dataTransfer . productionPackage ) ) {
654- return null
655- }
656- return getCurrentPlanUpgradelBalance ( dataTransfer . expire , dataTransfer . productionPackage , dataTransfer . isAnnual )
657-
658- } )
659-
660- this . totalAmount = ko . computed ( function ( ) {
661- const amount = ( Math . round ( ( self . payment ( ) - self . showCurrentPlanBalance ( ) ) * 100 ) / 100 ) . toString ( )
662- if ( ! / \. / . test ( amount ) ) {
663- return amount + '.00'
664- }
665- return amount
666- } )
667-
555+
668556 socketIo . on ( 'cardToken' , function ( err , res : QTGateAPIRequestCommand ) {
669557 const data = res . Args [ 0 ]
670558 self . doingPayment ( false )
@@ -684,14 +572,29 @@ class planUpgrade {
684572
685573 public showPayment ( payment : number , annually : boolean ) {
686574 this . detailArea ( false )
687- this . payment ( payment )
575+ this . payment ( payment / 100 )
688576 this . paymentAnnually ( annually )
689577 const currentPro = this . currentPromo ( ) . datePromo || 1
690578 let month = annually ? 12 * currentPro : 1
691- if ( this . currentPlan ( ) . name !== 'free' ) {
692-
693- }
694- const expir = getExpireWithMonths ( month )
579+
580+
581+ let expir = getExpireWithMonths ( month )
582+ // check is stoped monthly again
583+ if ( this . dataTransfer . productionPackage !== 'free' ) {
584+ if ( this . dataTransfer . isAnnual ) {
585+ const monthly = this . dataTransfer . paidAmount / this . dataTransfer . totalMonth
586+ this . CurrentPlanBalance ( getRemainingMonth ( this . dataTransfer . expire ) * monthly )
587+ } else {
588+ this . CurrentPlanBalance ( this . currentPlan ( ) . monthlyPay )
589+ }
590+ }
591+
592+ if ( ! annually ) {
593+ if ( this . plan . name === this . currentPlan ( ) . name ) {
594+ this . isAutomaticallyAgain ( true )
595+ expir = new Date ( this . dataTransfer . expire )
596+ }
597+ }
695598 this . newPlanExpirationYear ( expir . getFullYear ( ) . toString ( ) )
696599 const _month = expir . getMonth ( ) + 1
697600 if ( _month < 10 ) {
@@ -701,7 +604,12 @@ class planUpgrade {
701604 }
702605
703606 this . newPlanExpirationDay ( expir . getDate ( ) . toString ( ) )
704-
607+ if ( this . CurrentPlanBalance ( ) > - 1 ) {
608+ this . totalAmount ( this . payment ( ) - this . CurrentPlanBalance ( ) / 100 )
609+ } else {
610+ this . totalAmount ( this . payment ( ) )
611+ }
612+
705613 }
706614
707615 private showWaitPaymentFinished ( ) {
@@ -782,7 +690,7 @@ class planUpgrade {
782690 const self = this
783691 this . clearPaymentError ( )
784692 let handler = null
785- const amount = Math . round ( ( this . payment ( ) - this . showCurrentPlanBalance ( ) ) * 100 )
693+ const amount = this . totalAmount ( ) * 100
786694 if ( StripeCheckout && typeof StripeCheckout . configure === 'function' ) {
787695 handler = StripeCheckout . configure ( {
788696 key : Stripe_publicKey ,
@@ -838,15 +746,15 @@ class planUpgrade {
838746}
839747
840748class cancelPlan {
841- public passedMonth = getPassedMonth ( this . startDay )
749+ public passedMonth = getPassedMonth ( this . startDay ) + 1
842750 public passedCost = this . passedMonth * this . normailMonthPrice
843751 public balance = this . amount - this . passedCost
844752 public cancelProcess = ko . observable ( false )
845753 private doingProcessBarTime = null
846754 public showError = ko . observable ( false )
847755
848756 constructor ( public planName : string , public totalMonth , public amount , private startDay : string , public expir : string , public isAnnual ,
849- private normailMonthPrice : string , private exit : ( payment ) => void ) {
757+ private normailMonthPrice : number , private exit : ( payment ) => void ) {
850758 const self = this
851759
852760 }
@@ -997,12 +905,17 @@ class CoGateAccount {
997905
998906
999907 let plus1 = 1
1000- if ( ! this . dataTransfer . automatically && this . currentPlan . name ! == 'free' ) {
908+ if ( this . currentPlan . name = == 'free' ) {
1001909 plus1 = 0
1002910 }
911+
1003912 this . planArray ( ) [ 1 + plus1 ] . tail ( true )
1004- for ( let i = plan + plus1 ; i < planArray . length ; i ++ ) {
1005- this . planArray ( ) [ i ] . showButton ( true )
913+ if ( this . dataTransfer . productionPackage === 'p1' ) {
914+ this . planArray ( ) [ 1 ] . showButton ( false )
915+ }
916+ if ( this . dataTransfer . productionPackage === 'p2' ) {
917+ this . planArray ( ) [ 1 ] . showButton ( false )
918+ this . planArray ( ) [ 2 ] . showButton ( false )
1006919 }
1007920 const date = new Date ( dataTransfer . expire )
1008921 this . currentPlanExpirationYear ( date . getFullYear ( ) . toString ( ) )
@@ -1014,7 +927,7 @@ class CoGateAccount {
1014927 public selectPlan1 ( n : number ) {
1015928 let uu = null
1016929 const self = this
1017- this . planUpgrade ( uu = new planUpgrade ( n , this . dataTransfer . isAnnual , this . dataTransfer , function ( payment ) {
930+ return this . planUpgrade ( uu = new planUpgrade ( n , this . dataTransfer . isAnnual , this . dataTransfer , function ( payment ) {
1018931 self . planUpgrade ( uu = null )
1019932 self . exit ( payment )
1020933 } ) )
@@ -1056,7 +969,6 @@ class CoGateAccount {
1056969
1057970 } )
1058971
1059- return false
1060972 }
1061973
1062974 private showWaitPaymentFinished ( ) {
@@ -1085,7 +997,7 @@ class CoGateAccount {
1085997 let uu = null
1086998 const self = this
1087999 this . doingPayment ( true )
1088- this . cancelPlanData ( uu = new cancelPlan ( dataTransfer . productionPackage , dataTransfer . totalMonth , dataTransfer . paidAmount , dataTransfer . startDate , dataTransfer . expire , dataTransfer . isAnnual , this . currentPlan . monthlyPay ,
1000+ return this . cancelPlanData ( uu = new cancelPlan ( dataTransfer . productionPackage , dataTransfer . totalMonth , dataTransfer . paidAmount , dataTransfer . startDate , dataTransfer . expire , dataTransfer . isAnnual , this . currentPlan . monthlyPay ,
10891001 function exit ( payment ) {
10901002 self . cancelPlanData ( uu = null )
10911003 self . exit ( payment )
0 commit comments