@@ -84,9 +84,11 @@ public function sel_crypto()
8484 public function confirm ()
8585 {
8686 // Library
87+ $ this ->load ->language ('extension/cryptapi/payment/cryptapi ' );
8788 require (DIR_EXTENSION . 'cryptapi/system/library/cryptapi.php ' );
8889
8990 $ json = array ();
91+ $ err_coin = '' ;
9092
9193 if ($ this ->config ->get ('payment_cryptapi_status ' )) {
9294 $ this ->load ->model ('checkout/order ' );
@@ -95,13 +97,18 @@ public function confirm()
9597 $ order_info = $ this ->model_checkout_order ->getOrder ($ this ->session ->data ['order_id ' ]);
9698 $ cryptoFee = empty ($ this ->session ->data ['cryptapi_fee ' ]) ? 0 : $ this ->session ->data ['cryptapi_fee ' ];
9799 $ total = $ this ->currency ->format ($ order_info ['total ' ] + $ cryptoFee , $ order_info ['currency_code ' ], 1.00000 , false );
98-
99- $ selected = $ this ->request ->post ['cryptapi_coin ' ];
100- $ address = $ this ->config ->get ('payment_cryptapi_cryptocurrencies_address_ ' . $ selected );
101-
102100 $ apiKey = $ this ->config ->get ('payment_cryptapi_api_key ' );
101+ if (empty ($ this ->request ->post ['cryptapi_coin ' ])) {
102+ $ err_coin = $ this ->language ->get ('error_coin ' );
103+ } else {
104+ $ selected = $ this ->request ->post ['cryptapi_coin ' ];
105+ $ address = $ this ->config ->get ('payment_cryptapi_cryptocurrencies_address_ ' . $ selected );
106+ if (empty ($ address ) && empty ($ apiKey )) {
107+ $ err_coin = $ this ->language ->get ('error_apikey ' );
108+ }
109+ }
103110
104- if (!empty ($ address ) || !empty ($ apiKey )) {
111+ if (empty ( $ err_coin ) && ( !empty ($ address ) || !empty ($ apiKey) )) {
105112 $ nonce = $ this ->model_extension_cryptapi_payment_cryptapi ->generateNonce ();
106113
107114 $ disable_conversion = $ this ->config ->get ('payment_cryptapi_disable_conversion ' );
@@ -112,18 +119,20 @@ public function confirm()
112119
113120 $ cryptoTotal = \Opencart \Extension \CryptAPI \System \Library \CryptAPIHelper::get_conversion ($ order_info ['currency_code ' ], $ selected , $ total , $ disable_conversion );
114121
115- if ($ cryptoTotal < $ minTx ) {
116- $ message = $ this ->module ->l ('Payment error: ' , 'validation ' );
117- $ message .= $ this ->module ->l ('Value too low, minimum is ' , 'validation ' );
118- $ message .= ' ' . $ minTx . ' ' . strtoupper ($ selected );
119- $ json ['error ' ] = $ message ;
120- } else {
121- $ callbackUrl = $ this ->url ->link ('extension/cryptapi/payment/cryptapi|callback ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . '&nonce= ' . $ nonce , true );
122- $ callbackUrl = str_replace ('& ' , '& ' , $ callbackUrl );
122+ $ callbackUrl = $ this ->url ->link ('extension/cryptapi/payment/cryptapi|callback ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . '&nonce= ' . $ nonce , true );
123+ $ callbackUrl = str_replace ('& ' , '& ' , $ callbackUrl );
123124
124- $ helper = new \Opencart \Extension \CryptAPI \System \Library \CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , [], true );
125- $ addressIn = $ helper ->get_address ();
125+ $ helper = new \Opencart \Extension \CryptAPI \System \Library \CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , [], true );
126+ $ addressIn = $ helper ->get_address ();
127+ if (!isset ($ addressIn )) {
128+ $ err_coin = $ this ->language ->get ('error_adress ' );
129+ } else {
130+ if (($ cryptoTotal < $ minTx )) {
131+ $ err_coin = $ this ->language ->get ('value_minim ' ) . ' ' . $ minTx . ' ' . strtoupper ($ selected );
132+ }
133+ }
126134
135+ if (empty ($ err_coin )) {
127136 $ qrCodeDataValue = $ helper ->get_qrcode ($ cryptoTotal , $ qr_code_size );
128137 $ qrCodeData = $ helper ->get_qrcode ('' , $ qr_code_size );
129138 $ paymentURL = $ this ->url ->link ('extension/cryptapi/payment/cryptapi|pay ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . 'nonce= ' . $ nonce , true );
@@ -150,7 +159,11 @@ public function confirm()
150159
151160 $ this ->model_checkout_order ->addHistory ($ this ->session ->data ['order_id ' ], $ this ->config ->get ('payment_cryptapi_order_status_id ' ), '' , true );
152161 $ json ['redirect ' ] = $ this ->url ->link ('checkout/success ' , 'order_id= ' . $ this ->session ->data ['order_id ' ] . 'nonce= ' . $ nonce , true );
162+ } else {
163+ $ json ['error ' ]['warning ' ] = sprintf ($ this ->language ->get ('error_payment ' ), $ err_coin );
153164 }
165+ } else {
166+ $ json ['error ' ]['warning ' ] = sprintf ($ this ->language ->get ('error_payment ' ), $ err_coin );
154167 }
155168 }
156169
@@ -542,7 +555,7 @@ public function callback()
542555
543556 $ metaData = json_decode ($ this ->model_extension_cryptapi_payment_cryptapi ->getPaymentData ($ order ['order_id ' ]), true );
544557
545- $ history = json_decode ($ metaData ['cryptapi_history ' ], true );// <<-something's wrong
558+ $ history = json_decode ($ metaData ['cryptapi_history ' ], true ); // <<-something's wrong
546559
547560 $ calc = \Opencart \Extension \CryptAPI \System \Library \CryptAPIHelper::calc_order ($ history , $ metaData ['cryptapi_total ' ], $ metaData ['cryptapi_total_fiat ' ]);
548561
@@ -578,10 +591,10 @@ function order_pay_button(&$route, &$data, &$output)
578591
579592 $ orderFetch = $ this ->model_checkout_order ->getOrder ($ order_id );
580593 $ order = $ this ->model_extension_cryptapi_payment_cryptapi ->getOrder ($ order_id );
581-
594+
582595 $ orderObj = isset ($ order ['response ' ]) ? json_decode ($ order ['response ' ]) : '' ;
583596
584- if (!$ orderObj ) {
597+ if (!$ orderObj ) {
585598 return ;
586599 }
587600
@@ -590,4 +603,4 @@ function order_pay_button(&$route, &$data, &$output)
590603 $ data ['continue ' ] = $ orderObj ->cryptapi_payment_url ;
591604 }
592605 }
593- }
606+ }
0 commit comments