@@ -67,7 +67,9 @@ public function index()
6767
6868 public function confirm ()
6969 {
70+ $ this ->load ->language ('extension/payment/cryptapi ' );
7071 $ json = array ();
72+ $ err_coin = '' ;
7173
7274 if ($ this ->session ->data ['payment_method ' ]['code ' ] == 'cryptapi ' ) {
7375 $ this ->load ->model ('checkout/order ' );
@@ -78,12 +80,20 @@ public function confirm()
7880 $ total = $ this ->currency ->format ($ order_info ['total ' ] + $ cryptoFee , $ order_info ['currency_code ' ], 1.00000 , false );
7981 $ currency = $ this ->session ->data ['currency ' ];
8082
81- $ selected = $ this ->request ->post ['cryptapi_coin ' ];
82- $ address = $ this ->config ->get ('payment_cryptapi_cryptocurrencies_address_ ' . $ selected );
83-
8483 $ apiKey = $ this ->config ->get ('payment_cryptapi_api_key ' );
84+ if (empty ($ this ->request ->post ['cryptapi_coin ' ])) {
85+ $ err_coin = $ this ->language ->get ('error_coin ' );
86+ } else {
87+ $ selected = $ this ->request ->post ['cryptapi_coin ' ];
88+ $ address = $ this ->config ->get ('payment_cryptapi_cryptocurrencies_address_ ' . $ selected );
89+ if (empty ($ address ) && empty ($ apiKey )) {
90+ $ err_coin = $ this ->language ->get ('error_apikey ' );
91+ }
92+ }
93+
94+
8595
86- if (!empty ($ address ) || !empty ($ apiKey )) {
96+ if (empty ( $ err_coin ) && ( !empty ($ address ) || !empty ($ apiKey) )) {
8797 $ nonce = $ this ->model_extension_payment_cryptapi ->generateNonce ();
8898
8999 require_once (DIR_SYSTEM . 'library/cryptapi.php ' );
@@ -95,19 +105,21 @@ public function confirm()
95105 $ minTx = floatval ($ info ->minimum_transaction_coin );
96106
97107 $ cryptoTotal = CryptAPIHelper::get_conversion ($ order_info ['currency_code ' ], $ selected , $ total , $ disable_conversion );
108+ $ callbackUrl = $ this ->url ->link ('extension/payment/cryptapi/callback ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . '&nonce= ' . $ nonce , true );
109+ $ callbackUrl = str_replace ('& ' , '& ' , $ callbackUrl );
98110
99- if ($ cryptoTotal < $ minTx ) {
100- $ message = $ this ->module ->l ('Payment error: ' , 'validation ' );
101- $ message .= $ this ->module ->l ('Value too low, minimum is ' , 'validation ' );
102- $ message .= ' ' . $ minTx . ' ' . strtoupper ($ selected );
103- $ json ['error ' ] = $ message ;
104- } else {
105- $ callbackUrl = $ this ->url ->link ('extension/payment/cryptapi/callback ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . '&nonce= ' . $ nonce , true );
106- $ callbackUrl = str_replace ('& ' , '& ' , $ callbackUrl );
111+ $ helper = new CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , [], true );
112+ $ addressIn = $ helper ->get_address ();
107113
114+ if (!isset ($ addressIn )) {
115+ $ err_coin = $ this ->language ->get ('error_adress ' );
116+ } else {
117+ if (($ cryptoTotal < $ minTx )) {
118+ $ err_coin = $ this ->language ->get ('value_minim ' ) . ' ' . $ minTx . ' ' . strtoupper ($ selected );
119+ }
120+ }
108121
109- $ helper = new CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , [], true );
110- $ addressIn = $ helper ->get_address ();
122+ if (empty ($ err_coin )) {
111123
112124 $ qrCodeDataValue = $ helper ->get_qrcode ($ cryptoTotal , $ qr_code_size );
113125 $ qrCodeData = $ helper ->get_qrcode ('' , $ qr_code_size );
@@ -135,7 +147,11 @@ public function confirm()
135147
136148 $ this ->model_checkout_order ->addOrderHistory ($ this ->session ->data ['order_id ' ], $ this ->config ->get ('payment_cryptapi_order_status_id ' ));
137149 $ json ['redirect ' ] = $ this ->url ->link ('checkout/success ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . 'nonce= ' . $ nonce , true );
150+ } else {
151+ $ json ['error ' ]['warning ' ] = sprintf ($ this ->language ->get ('error_payment ' ), $ err_coin );
138152 }
153+ } else {
154+ $ json ['error ' ]['warning ' ] = sprintf ($ this ->language ->get ('error_payment ' ), $ err_coin );
139155 }
140156 }
141157
@@ -242,7 +258,7 @@ public function pay()
242258 'qr_code ' => $ metaData ['cryptapi_qrcode ' ],
243259 'qr_code_value ' => $ metaData ['cryptapi_qrcode_value ' ],
244260 'show_branding ' => $ this ->config ->get ('payment_cryptapi_branding ' ),
245- 'branding_logo ' => HTTPS_SERVER . 'image/catalog/cryptapi/payment.png ' ,
261+ 'branding_logo ' => HTTPS_SERVER . 'image/catalog/cryptapi/payment.png ' ,
246262 'qr_code_setting ' => $ this ->config ->get ('payment_cryptapi_qrcode ' ),
247263 'order_timestamp ' => $ order ['total ' ],
248264 'order_cancelation_timeout ' => $ this ->config ->get ('payment_cryptapi_order_cancelation_timeout ' ),
@@ -469,7 +485,7 @@ public function cron()
469485 $ this ->model_extension_payment_cryptapi ->updatePaymentData ($ order_id , 'cryptapi_last_price_update ' , time ());
470486 }
471487
472- if ($ order_timeout !== 0 && (strtotime ($ order ['date_added ' ]) + $ order_timeout ) <= time () && $ already_paid <=0 && (int )$ metaData ['cryptapi_cancelled ' ] === 0 ) {
488+ if ($ order_timeout !== 0 && (strtotime ($ order ['date_added ' ]) + $ order_timeout ) <= time () && $ already_paid <= 0 && (int )$ metaData ['cryptapi_cancelled ' ] === 0 ) {
473489 $ this ->model_checkout_order ->addOrderHistory ($ order ['order_id ' ], 7 );
474490 $ this ->model_extension_payment_cryptapi ->updatePaymentData ($ order_id , 'cryptapi_cancelled ' , '1 ' );
475491 }
@@ -523,7 +539,7 @@ public function callback()
523539
524540 $ metaData = json_decode ($ this ->model_extension_payment_cryptapi ->getPaymentData ($ order ['order_id ' ]), true );
525541
526- $ history = json_decode ($ metaData ['cryptapi_history ' ], true );// <<-something's wrong
542+ $ history = json_decode ($ metaData ['cryptapi_history ' ], true ); // <<-something's wrong
527543
528544 $ calc = CryptAPIHelper::calc_order ($ history , $ metaData ['cryptapi_total ' ], $ metaData ['cryptapi_total_fiat ' ]);
529545
@@ -562,7 +578,7 @@ function order_pay_button(&$route, &$data, &$output)
562578
563579 $ orderObj = isset ($ order ['response ' ]) ? json_decode ($ order ['response ' ]) : '' ;
564580
565- if (!$ orderObj ) {
581+ if (!$ orderObj ) {
566582 return ;
567583 }
568584
@@ -571,4 +587,4 @@ function order_pay_button(&$route, &$data, &$output)
571587 $ data ['continue ' ] = $ orderObj ->cryptapi_payment_url ;
572588 }
573589 }
574- }
590+ }
0 commit comments