@@ -37,105 +37,109 @@ public function __construct(
3737
3838 public function getTemplateValues ()
3939 {
40- if ($ this ->productMetadata ->getVersion () >= 2.3 && $ this ->productMetadata ->getVersion () < 2.4 ) {
41- $ order = $ this ->payment ->getOrder ();
42- } else {
43- $ order_id = (int )$ this ->request ->getParam ('order_id ' );
44- $ nonce = (string )$ this ->request ->getParam ('nonce ' );
45- $ order = $ this ->orderRepository ->get ($ order_id );
46- }
40+ try {
41+ if ($ this ->productMetadata ->getVersion () >= 2.3 && $ this ->productMetadata ->getVersion () < 2.4 ) {
42+ $ order = $ this ->payment ->getOrder ();
43+ } else {
44+ $ order_id = (int )$ this ->request ->getParam ('order_id ' );
45+ $ nonce = (string )$ this ->request ->getParam ('nonce ' );
46+ $ order = $ this ->orderRepository ->get ($ order_id );
47+ }
4748
48- $ total = $ order ->getGrandTotal ();
49- $ currencySymbol = $ order ->getOrderCurrencyCode ();
50- $ metaData = $ this ->helper ->getPaymentResponse ($ order ->getQuoteId ());
49+ $ total = $ order ->getGrandTotal ();
50+ $ currencySymbol = $ order ->getOrderCurrencyCode ();
51+ $ metaData = $ this ->helper ->getPaymentResponse ($ order ->getQuoteId ());
5152
52- if (empty ($ metaData )) {
53- return false ;
54- }
53+ if (empty ($ metaData )) {
54+ return false ;
55+ }
5556
56- $ qrCodeSize = $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_size ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
57+ $ qrCodeSize = $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_size ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
5758
58- $ branding = $ this ->scopeConfig ->getValue ('payment/cryptapi/show_branding ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
59+ $ branding = $ this ->scopeConfig ->getValue ('payment/cryptapi/show_branding ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
5960
60- $ metaData = json_decode ($ metaData , true );
61+ $ metaData = json_decode ($ metaData , true );
6162
62- if ($ nonce != $ metaData ['cryptapi_nonce ' ]) {
63- return false ;
64- }
63+ if ($ nonce != $ metaData ['cryptapi_nonce ' ]) {
64+ return false ;
65+ }
6566
66- $ cryptoValue = $ metaData ['cryptapi_total ' ];
67- $ cryptoCoin = $ metaData ['cryptapi_currency ' ];
67+ $ cryptoValue = $ metaData ['cryptapi_total ' ];
68+ $ cryptoCoin = $ metaData ['cryptapi_currency ' ];
6869
69- if (isset ($ metaData ['cryptapi_address ' ]) && !empty ($ metaData ['cryptapi_address ' ])) {
70- $ addressIn = $ metaData ['cryptapi_address ' ];
71- } else {
72- /*
73- * Makes request to API and generates all the payment data needed
74- */
70+ if (isset ($ metaData ['cryptapi_address ' ]) && !empty ($ metaData ['cryptapi_address ' ])) {
71+ $ addressIn = $ metaData ['cryptapi_address ' ];
72+ } else {
73+ /*
74+ * Makes request to API and generates all the payment data needed
75+ */
7576
76- $ selected = $ cryptoCoin ;
77+ $ selected = $ cryptoCoin ;
7778
78- $ address = '' ;
79+ $ address = '' ;
7980
80- $ allCryptocurrencies = json_decode ($ this ->scopeConfig ->getValue ('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ), true );
81+ $ allCryptocurrencies = json_decode ($ this ->scopeConfig ->getValue ('payment/cryptapi/supported_cryptocurrencies/cryptocurrencies ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ), true );
8182
82- foreach ($ allCryptocurrencies as $ uid => $ data ) {
83- if ($ data ['cryptocurrency ' ] === $ selected ) {
84- $ address = $ data ['cryptocurrency_address ' ];
83+ foreach ($ allCryptocurrencies as $ uid => $ data ) {
84+ if ($ data ['cryptocurrency ' ] === $ selected ) {
85+ $ address = $ data ['cryptocurrency_address ' ];
86+ }
8587 }
86- }
8788
88- $ params = [
89- 'order_id ' => $ order ->getId (),
90- 'nonce ' => $ metaData ['cryptapi_nonce ' ],
91- ];
89+ $ params = [
90+ 'order_id ' => $ order ->getId (),
91+ 'nonce ' => $ metaData ['cryptapi_nonce ' ],
92+ ];
9293
93- $ callbackUrl = $ this ->payment ->getCallbackUrl ();
94+ $ callbackUrl = $ this ->payment ->getCallbackUrl ();
9495
95- $ apiKey = $ this ->scopeConfig ->getValue ('payment/cryptapi/api_key ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
96+ $ apiKey = $ this ->scopeConfig ->getValue ('payment/cryptapi/api_key ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
9697
97- $ api = new CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , $ params , true );
98- $ addressIn = $ api ->get_address ();
98+ $ api = new CryptAPIHelper ($ selected , $ address , $ apiKey , $ callbackUrl , $ params , true );
99+ $ addressIn = $ api ->get_address ();
99100
100- $ qrCode = $ api ->get_qrcode ('' , $ qrCodeSize );
101- $ qrCodeValue = $ api ->get_qrcode ($ cryptoValue , $ qrCodeSize );
101+ $ qrCode = $ api ->get_qrcode ('' , $ qrCodeSize );
102+ $ qrCodeValue = $ api ->get_qrcode ($ cryptoValue , $ qrCodeSize );
102103
103- $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_address ' , $ addressIn );
104- $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_qr_code_value ' , $ qrCodeValue ['qr_code ' ]);
105- $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_qr_code ' , $ qrCode ['qr_code ' ]);
106- $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_payment_url ' , $ this ->storeManager ->getStore ()->getUrl ('cryptapi/index/payment/order_id/ ' . $ order ->getId () . '/nonce/ ' . $ metaData ['cryptapi_nonce ' ]));
104+ $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_address ' , $ addressIn );
105+ $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_qr_code_value ' , $ qrCodeValue ['qr_code ' ]);
106+ $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_qr_code ' , $ qrCode ['qr_code ' ]);
107+ $ this ->helper ->updatePaymentData ($ order ->getQuoteId (), 'cryptapi_payment_url ' , $ this ->storeManager ->getStore ()->getUrl ('cryptapi/index/payment/order_id/ ' . $ order ->getId () . '/nonce/ ' . $ metaData ['cryptapi_nonce ' ]));
107108
108- $ metaData = json_decode ($ this ->helper ->getPaymentResponse ($ order ->getQuoteId ()), true );
109- $ this ->mail ->sendMail ($ order , $ metaData );
110- }
109+ $ metaData = json_decode ($ this ->helper ->getPaymentResponse ($ order ->getQuoteId ()), true );
110+ $ this ->mail ->sendMail ($ order , $ metaData );
111+ }
112+
113+ $ ajaxParams = [
114+ 'order_id ' => $ order ->getId (),
115+ ];
111116
112- $ ajaxParams = [
113- 'order_id ' => $ order ->getId (),
114- ];
115-
116- $ ajaxUrl = $ this ->payment ->getAjaxStatusUrl ($ ajaxParams );
117-
118- $ metaData = $ this ->helper ->getPaymentResponse ($ order ->getQuoteId ());
119- $ metaData = json_decode ($ metaData , true );
120-
121- return [
122- 'crypto_value ' => floatval ($ cryptoValue ),
123- 'currency_symbol ' => $ currencySymbol ,
124- 'total ' => $ total ,
125- 'address_in ' => $ addressIn ,
126- 'crypto_coin ' => $ cryptoCoin ,
127- 'ajax_url ' => $ ajaxUrl ,
128- 'qrcode_size ' => $ qrCodeSize ,
129- 'qrcode ' => $ metaData ['cryptapi_qr_code ' ],
130- 'qrcode_value ' => $ metaData ['cryptapi_qr_code_value ' ],
131- 'qrcode_default ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_default ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
132- 'show_branding ' => $ branding ,
133- 'qr_code_setting ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_setting ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
134- 'order_timestamp ' => strtotime ($ order ->getCreatedAt ()),
135- 'order_cancelation_timeout ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/order_cancelation_timeout ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
136- 'refresh_value_interval ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/refresh_value_interval ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
137- 'last_price_update ' => $ metaData ['cryptapi_last_price_update ' ],
138- 'min_tx ' => $ metaData ['cryptapi_min ' ],
139- ];
117+ $ ajaxUrl = $ this ->payment ->getAjaxStatusUrl ($ ajaxParams );
118+
119+ $ metaData = $ this ->helper ->getPaymentResponse ($ order ->getQuoteId ());
120+ $ metaData = json_decode ($ metaData , true );
121+
122+ return [
123+ 'crypto_value ' => floatval ($ cryptoValue ),
124+ 'currency_symbol ' => $ currencySymbol ,
125+ 'total ' => $ total ,
126+ 'address_in ' => $ addressIn ,
127+ 'crypto_coin ' => $ cryptoCoin ,
128+ 'ajax_url ' => $ ajaxUrl ,
129+ 'qrcode_size ' => $ qrCodeSize ,
130+ 'qrcode ' => $ metaData ['cryptapi_qr_code ' ],
131+ 'qrcode_value ' => $ metaData ['cryptapi_qr_code_value ' ],
132+ 'qrcode_default ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_default ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
133+ 'show_branding ' => $ branding ,
134+ 'qr_code_setting ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/qrcode_setting ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
135+ 'order_timestamp ' => strtotime ($ order ->getCreatedAt ()),
136+ 'order_cancelation_timeout ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/order_cancelation_timeout ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
137+ 'refresh_value_interval ' => $ this ->scopeConfig ->getValue ('payment/cryptapi/refresh_value_interval ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE ),
138+ 'last_price_update ' => $ metaData ['cryptapi_last_price_update ' ],
139+ 'min_tx ' => $ metaData ['cryptapi_min ' ],
140+ ];
141+ } catch (\Exception $ exception ) {
142+ // Empty
143+ }
140144 }
141145}
0 commit comments