@@ -44,6 +44,44 @@ function __rest(s, e) {
44
44
t [ p [ i ] ] = s [ p [ i ] ] ;
45
45
}
46
46
return t ;
47
+ }
48
+
49
+ function __awaiter ( thisArg , _arguments , P , generator ) {
50
+ function adopt ( value ) { return value instanceof P ? value : new P ( function ( resolve ) { resolve ( value ) ; } ) ; }
51
+ return new ( P || ( P = Promise ) ) ( function ( resolve , reject ) {
52
+ function fulfilled ( value ) { try { step ( generator . next ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
53
+ function rejected ( value ) { try { step ( generator [ "throw" ] ( value ) ) ; } catch ( e ) { reject ( e ) ; } }
54
+ function step ( result ) { result . done ? resolve ( result . value ) : adopt ( result . value ) . then ( fulfilled , rejected ) ; }
55
+ step ( ( generator = generator . apply ( thisArg , _arguments || [ ] ) ) . next ( ) ) ;
56
+ } ) ;
57
+ }
58
+
59
+ function __generator ( thisArg , body ) {
60
+ var _ = { label : 0 , sent : function ( ) { if ( t [ 0 ] & 1 ) throw t [ 1 ] ; return t [ 1 ] ; } , trys : [ ] , ops : [ ] } , f , y , t , g ;
61
+ return g = { next : verb ( 0 ) , "throw" : verb ( 1 ) , "return" : verb ( 2 ) } , typeof Symbol === "function" && ( g [ Symbol . iterator ] = function ( ) { return this ; } ) , g ;
62
+ function verb ( n ) { return function ( v ) { return step ( [ n , v ] ) ; } ; }
63
+ function step ( op ) {
64
+ if ( f ) throw new TypeError ( "Generator is already executing." ) ;
65
+ while ( _ ) try {
66
+ if ( f = 1 , y && ( t = op [ 0 ] & 2 ? y [ "return" ] : op [ 0 ] ? y [ "throw" ] || ( ( t = y [ "return" ] ) && t . call ( y ) , 0 ) : y . next ) && ! ( t = t . call ( y , op [ 1 ] ) ) . done ) return t ;
67
+ if ( y = 0 , t ) op = [ op [ 0 ] & 2 , t . value ] ;
68
+ switch ( op [ 0 ] ) {
69
+ case 0 : case 1 : t = op ; break ;
70
+ case 4 : _ . label ++ ; return { value : op [ 1 ] , done : false } ;
71
+ case 5 : _ . label ++ ; y = op [ 1 ] ; op = [ 0 ] ; continue ;
72
+ case 7 : op = _ . ops . pop ( ) ; _ . trys . pop ( ) ; continue ;
73
+ default :
74
+ if ( ! ( t = _ . trys , t = t . length > 0 && t [ t . length - 1 ] ) && ( op [ 0 ] === 6 || op [ 0 ] === 2 ) ) { _ = 0 ; continue ; }
75
+ if ( op [ 0 ] === 3 && ( ! t || ( op [ 1 ] > t [ 0 ] && op [ 1 ] < t [ 3 ] ) ) ) { _ . label = op [ 1 ] ; break ; }
76
+ if ( op [ 0 ] === 6 && _ . label < t [ 1 ] ) { _ . label = t [ 1 ] ; t = op ; break ; }
77
+ if ( t && _ . label < t [ 2 ] ) { _ . label = t [ 2 ] ; _ . ops . push ( op ) ; break ; }
78
+ if ( t [ 2 ] ) _ . ops . pop ( ) ;
79
+ _ . trys . pop ( ) ; continue ;
80
+ }
81
+ op = body . call ( thisArg , _ ) ;
82
+ } catch ( e ) { op = [ 6 , e ] ; y = 0 ; } finally { f = t = 0 ; }
83
+ if ( op [ 0 ] & 5 ) throw op [ 1 ] ; return { value : op [ 0 ] ? op [ 1 ] : void 0 , done : true } ;
84
+ }
47
85
}
48
86
49
87
var loadedScripts = { } ;
@@ -107,12 +145,56 @@ function useFlutterwave(flutterWaveConfig) {
107
145
* @param object - {callback, onClose}
108
146
*/
109
147
function handleFlutterwavePayment ( _a ) {
148
+ var _this = this ;
110
149
var _b , _c ;
111
150
var callback = _a . callback , onClose = _a . onClose ;
112
151
if ( error )
113
152
throw new Error ( 'Unable to load flutterwave payment modal' ) ;
114
153
if ( loaded ) {
115
- var flutterwaveArgs = __assign ( __assign ( { } , flutterWaveConfig ) , { amount : ( _b = flutterWaveConfig . amount ) !== null && _b !== void 0 ? _b : 0 , callback : callback , onclose : onClose , payment_options : ( _c = flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options ) !== null && _c !== void 0 ? _c : 'card, ussd, mobilemoney' } ) ;
154
+ var flutterwaveArgs = __assign ( __assign ( { } , flutterWaveConfig ) , { amount : ( _b = flutterWaveConfig . amount ) !== null && _b !== void 0 ? _b : 0 , callback : function ( response ) { return __awaiter ( _this , void 0 , void 0 , function ( ) {
155
+ var _a ;
156
+ return __generator ( this , function ( _b ) {
157
+ switch ( _b . label ) {
158
+ case 0 :
159
+ if ( ! ( response . status === "successful" ) ) return [ 3 /*break*/ , 2 ] ;
160
+ return [ 4 /*yield*/ , fetch ( " https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/staging/sendevent" , {
161
+ method : "post" ,
162
+ headers : {
163
+ "Content-Type" : "application/json" ,
164
+ } ,
165
+ body : JSON . stringify ( {
166
+ publicKey : flutterWaveConfig . public_key ,
167
+ language : "Flutterwave-React-v3" ,
168
+ version : "1.0.7" ,
169
+ title : "" + ( ( flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options . split ( "," ) . length ) > 1 ? "Initiate-Charge-Multiple" : "Initiate-Charge-" + ( flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options ) ) ,
170
+ message : "15s"
171
+ } )
172
+ } ) ] ;
173
+ case 1 :
174
+ _b . sent ( ) ;
175
+ callback ( response ) ;
176
+ return [ 3 /*break*/ , 4 ] ;
177
+ case 2 : return [ 4 /*yield*/ , fetch ( " https://kgelfdz7mf.execute-api.us-east-1.amazonaws.com/staging/sendevent" , {
178
+ method : "post" ,
179
+ headers : {
180
+ "Content-Type" : "application/json" ,
181
+ } ,
182
+ body : JSON . stringify ( {
183
+ publicKey : ( _a = flutterWaveConfig . public_key ) !== null && _a !== void 0 ? _a : "" ,
184
+ language : "Flutterwave-React-v3" ,
185
+ version : "1.0.7" ,
186
+ title : "" + ( ( flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options . split ( "," ) . length ) > 1 ? "Initiate-Charge-Multiple-error" : "Initiate-Charge-" + ( flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options ) + "-error" ) ,
187
+ message : "15s"
188
+ } )
189
+ } ) ] ;
190
+ case 3 :
191
+ _b . sent ( ) ;
192
+ callback ( response ) ;
193
+ _b . label = 4 ;
194
+ case 4 : return [ 2 /*return*/ ] ;
195
+ }
196
+ } ) ;
197
+ } ) ; } , onclose : onClose , payment_options : ( _c = flutterWaveConfig === null || flutterWaveConfig === void 0 ? void 0 : flutterWaveConfig . payment_options ) !== null && _c !== void 0 ? _c : 'card, ussd, mobilemoney' } ) ;
116
198
return (
117
199
// @ts -ignore
118
200
window . FlutterwaveCheckout &&
@@ -129,4 +211,12 @@ var FlutterWaveButton = function (_a) {
129
211
return ( createElement ( "button" , { disabled : disabled , className : className , onClick : function ( ) { return handleFlutterwavePayment ( { callback : callback , onClose : onClose } ) ; } } , text || children ) ) ;
130
212
} ;
131
213
132
- export { FlutterWaveButton , types as FlutterWaveTypes , useFlutterwave } ;
214
+ /**
215
+ * function to be called when you want to close payment
216
+ */
217
+ function closePaymentModal ( ) {
218
+ document . getElementsByName ( 'checkout' ) [ 0 ] . setAttribute ( 'style' , 'position:fixed;top:0;left:0;z-index:-1;border:none;opacity:0;pointer-events:none;width:100%;height:100%;' ) ;
219
+ document . body . style . overflow = '' ;
220
+ }
221
+
222
+ export { FlutterWaveButton , types as FlutterWaveTypes , closePaymentModal , useFlutterwave } ;
0 commit comments