1
1
import { CurrencyPipe } from '@angular/common' ;
2
2
import { Component } from '@angular/core' ;
3
3
import { ICulqiOptions , IOrderCulqiResponse , NgxCulqiService } from 'ngx-culqi' ;
4
- import { environment } from '../../../environments/environment ' ;
4
+ import { FormsModule } from '@angular/forms ' ;
5
5
6
6
@Component ( {
7
7
selector : 'app-cart' ,
8
8
standalone : true ,
9
- imports : [ CurrencyPipe ] ,
9
+ imports : [ CurrencyPipe , FormsModule ] ,
10
10
templateUrl : './cart.component.html' ,
11
11
styleUrl : './cart.component.scss'
12
12
} )
@@ -23,6 +23,11 @@ export class CartComponent {
23
23
] ;
24
24
amountTotal = 400 ;
25
25
26
+ tokenCulqi : string = '' ;
27
+ apiKeyCulqi : string = '' ;
28
+ xculqirsaid : string = '' ;
29
+ rsapublickey : string = `` ;
30
+
26
31
styleCulqi = {
27
32
logo : 'https://developers.google.com/static/homepage-assets/images/angular_gradient.png' ,
28
33
bannerColor : '#5C44E4' ,
@@ -38,7 +43,6 @@ export class CartComponent {
38
43
constructor ( private ngxCulqiService : NgxCulqiService ) { }
39
44
40
45
ngOnInit ( ) : void {
41
- this . ngxCulqiService . loadScriptCulqi ( environment . tokenCulqi , environment . apiKeyCulqi ) ;
42
46
this . ngxCulqiService . tokenCreated$ . subscribe ( value => {
43
47
if ( value ) {
44
48
this . showToken ( value ) ;
@@ -54,6 +58,8 @@ export class CartComponent {
54
58
}
55
59
56
60
paymentCulqi ( ) : void {
61
+ // This function must be called from ngOnInit. Just for this example, it is inside the payment with a setTimeOut to be set from the form.
62
+ this . ngxCulqiService . loadScriptCulqi ( this . tokenCulqi , this . apiKeyCulqi ) ;
57
63
const order = {
58
64
"amount" : this . amountTotal * 100 ,
59
65
"currency_code" : "PEN" ,
@@ -68,19 +74,21 @@ export class CartComponent {
68
74
"expiration_date" : ( Math . floor ( Date . now ( ) / 1000 ) + 86400 ) ,
69
75
"confirm" : false
70
76
} ;
71
- this . ngxCulqiService . generateOrder ( order ) . subscribe ( ( response : Partial < IOrderCulqiResponse > ) => {
72
- const culqiSettings = {
73
- title : order . description ,
74
- currency : 'PEN' ,
75
- amount : order . amount ,
76
- order : response . id ,
77
- xculqirsaid : environment . xculqirsaid ,
78
- rsapublickey : environment . rsapublickey
79
- } ;
77
+ setTimeout ( ( ) => {
78
+ this . ngxCulqiService . generateOrder ( order ) . subscribe ( ( response : Partial < IOrderCulqiResponse > ) => {
79
+ const culqiSettings = {
80
+ title : order . description ,
81
+ currency : 'PEN' ,
82
+ amount : order . amount ,
83
+ order : response . id ,
84
+ xculqirsaid : this . xculqirsaid ,
85
+ rsapublickey : this . rsapublickey
86
+ } ;
80
87
81
- const culqiOptions : ICulqiOptions = { style : this . styleCulqi } ;
82
- this . ngxCulqiService . generateToken ( culqiSettings , culqiOptions ) ;
83
- } ) ;
88
+ const culqiOptions : ICulqiOptions = { style : this . styleCulqi } ;
89
+ this . ngxCulqiService . generateToken ( culqiSettings , culqiOptions ) ;
90
+ } ) ;
91
+ } , 3000 ) ;
84
92
}
85
93
86
94
showToken ( token : string ) : void {
0 commit comments