Changeset 2946797
- Timestamp:
- 08/02/2023 08:08:57 PM (2 years ago)
- Location:
- helcim-commerce-for-woocommerce
- Files:
-
- 2 added
- 6 edited
-
assets/icon-128x128.png (added)
-
trunk/WCHelcimGateway.php (modified) (15 diffs)
-
trunk/classes/HelcimApiFactory.php (added)
-
trunk/classes/HelcimCurl.php (modified) (5 diffs)
-
trunk/classes/HelcimDirectService.php (modified) (10 diffs)
-
trunk/index.php (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
helcim-commerce-for-woocommerce/trunk/WCHelcimGateway.php
r2893666 r2946797 11 11 require_once 'classes/HelcimCurl.php'; 12 12 require_once 'classes/HelcimDirectService.php'; 13 require_once 'classes/HelcimApiFactory.php'; 13 14 14 15 /** … … 20 21 * @class WCHelcimGateway 21 22 * @extends WC_Payment_Gateway 22 * @version 3.0.723 * @version 4.0.0 23 24 * @author Helcim Inc. 24 25 */ … … 29 30 private const GOOGLE_RECAPTCHA_TEST_SITE_KEY = '6LcgxK0UAAAAAH9gzsILRr82KZSLrBcry9RynMn4'; 30 31 private const GOOGLE_RECAPTCHA_LIVE_SITE_KEY = '6LdixK0UAAAAABmBXVo_jyFJSkQ5Doj9kloLyxGG'; 32 private const TRANSACTION_TYPE_PURCHASE = 'purchase'; 33 private const TRANSACTION_TYPE_PREAUTH = 'preauth'; 31 34 32 35 public const PLUGIN_NAME = 'woocommerce'; 33 public const VERSION = ' 3.0.7';36 public const VERSION = '4.0.0'; 34 37 public const HELCIM_CARD_TOKEN = 'helcim-card-token'; 38 /** 39 * @deprecated please use self::API_V2_ENDPOINT 40 */ 35 41 public const API_ENDPOINT = 'https://secure.myhelcim.com/api/'; 42 public const API_V2_ENDPOINT = 'https://api.helcim.com/v2/'; 36 43 public const HELCIM_SERVER_TIMEZONE = 'America/Edmonton'; 37 44 public const FORCE_HELCIM_JS_TO_RUN_VERIFY = 1; … … 43 50 private $accountId; 44 51 private $apiToken; 52 private $apiTokenV2; 45 53 private $show_logo; 46 54 private $transactionType; … … 66 74 $this->accountId = $this->get_option('accountId'); 67 75 $this->apiToken = $this->get_option('apiToken'); 76 $this->apiTokenV2 = $this->get_option('apiTokenV2'); 68 77 $this->title = ''; 69 78 $this->description = $this->get_option('description'); … … 121 130 { 122 131 return $this->apiToken; 132 } 133 134 public function getAPITokenV2(): string 135 { 136 return $this->apiTokenV2; 123 137 } 124 138 … … 174 188 { 175 189 $methods = ['js' => __('Helcim JS', 'woocommerce'), 'direct' => __('Direct Integration')]; 176 $transactionTypes = ['purchase' => __('Purchase', 'woocommerce'), 'preauth' => __('Pre-Authorization')]; 190 $transactionTypes = [ 191 self::TRANSACTION_TYPE_PURCHASE => __('Purchase', 'woocommerce'), 192 self::TRANSACTION_TYPE_PREAUTH => __('Pre-Authorization') 193 ]; 177 194 $this->form_fields['enabled'] = [ 178 195 'title' => __('Enable/Disable', 'woocommerce'), … … 184 201 'title' => __('Test', 'woocommerce'), 185 202 'type' => 'checkbox', 203 'description' => __('Only used for verify transactions. Purchase & preauth will not be processed as test. please assign a demo terminal to your currency in commerce if you want to run a test purchase or preauth', 'woocommerce'), 186 204 'label' => __('Test Mode', 'woocommerce'), 187 205 'default' => 'no' … … 192 210 'options' => $methods, 193 211 'description' => __( 194 'Choose between using Helcim.js and Direct Integration - <a href="https:// support.helcim.com/article/helcim-commerce-new-ui-integrations-woocommerce-integration-woocommerce/" target="_blank">Support Page</a>',212 'Choose between using Helcim.js and Direct Integration - <a href="https://learn.helcim.com/docs/accepting-payments-using-woocommerce" target="_blank">Support Page</a>', 195 213 'woocommerce' 196 214 ), … … 218 236 'default' => '' 219 237 ]; 220 $this->form_fields['apiToken '] = [238 $this->form_fields['apiTokenV2'] = [ 221 239 'title' => __('API Token', 'woocommerce'), 222 240 'type' => 'text', 223 241 'description' => __('Your Helcim Commerce API Token', 'woocommerce'), 224 'default' => '' 242 'default' => '', 243 ]; 244 $this->form_fields['apiToken'] = [ 245 'title' => __('API Token - Deprecated', 'woocommerce'), 246 'type' => 'text', 247 'description' => __('Deprecated. Please fill API Token instead', 'woocommerce'), 248 'default' => '', 249 'custom_attributes' => [ 250 'disabled' => 'disabled', 251 ], 225 252 ]; 226 253 $this->form_fields['transactionType'] = [ … … 232 259 ]; 233 260 $this->form_fields['terminalId'] = [ 234 'title' => __('Terminal Id ', 'woocommerce'),261 'title' => __('Terminal Id - Deprecated', 'woocommerce'), 235 262 'type' => 'number', 236 'description' => __('Commerce Terminal Id', 'woocommerce'), 237 'default' => '0' 263 'description' => __('Deprecated. Default terminal for the currency will be used', 'woocommerce'), 264 'default' => '0', 265 'custom_attributes' => [ 266 'disabled' => 'disabled', 267 ], 238 268 ]; 239 269 $this->form_fields['description'] = [ … … 280 310 } 281 311 if (!$this->getHelcimDirectService() instanceof HelcimDirectService) { 282 $this->setHelcimDirectService(new HelcimDirectService( ));312 $this->setHelcimDirectService(new HelcimDirectService(new HelcimCurl())); 283 313 } 284 314 $order = wc_get_order($orderId); … … 308 338 ]; 309 339 } 310 $xmlObject = $this->getHelcimDirectService()->processPurchasePreauth($order, $this); 311 if (!$xmlObject instanceof SimpleXMLElement) { 312 wc_add_notice('<b>Payment error:</b> Something went wrong please contact the Merchant', 'error'); 313 self::log("ORDER {$order->get_id()} ERROR - {$this->getHelcimDirectService()->getError()}"); 314 $order->add_order_note( 315 "Helcim Payment Failed - {$this->getHelcimDirectService()->getError()}" 340 if(empty($this->apiTokenV2)){ 341 // todo remove whole if condition 342 $xmlObject = $this->getHelcimDirectService()->processPurchasePreauth($order, $this); 343 if (!$xmlObject instanceof SimpleXMLElement) { 344 wc_add_notice('<b>Payment error:</b> Something went wrong please contact the Merchant', 'error'); 345 self::log("ORDER {$order->get_id()} ERROR - {$this->getHelcimDirectService()->getError()}"); 346 $order->add_order_note( 347 "Helcim Payment Failed - {$this->getHelcimDirectService()->getError()}" 348 ); 349 return []; 350 } 351 $this->completeOrder( 352 $order, 353 (string)$xmlObject->transaction->approvalCode ?: '', 354 isset($xmlObject->transaction->transactionId) ? (string)$xmlObject->transaction->transactionId : '0', 355 (string)$xmlObject->transaction->cardToken ?: '' 316 356 ); 317 return []; 318 } 319 $this->completeOrder( 320 $order, 321 (string)$xmlObject->transaction->approvalCode ?: '', 322 isset($xmlObject->transaction->transactionId) ? (string)$xmlObject->transaction->transactionId : '0', 323 (string)$xmlObject->transaction->cardToken ?: '' 324 ); 357 }else{ 358 $responsePayload = []; 359 360 // create customer 361 $customerCode = ''; 362 if(!empty($_POST['customerCode']) && $this->isJS()){ 363 $customerCode = (string)$_POST['customerCode']; 364 if(get_current_user_id() && (string)$_POST['customerCode'] !== (string)get_current_user_id()){ 365 $customerCode = (string)get_current_user_id(); 366 $customerIdOld = $this->getHelcimDirectService()->getCustomerId((string)$_POST['customerCode'], $this); 367 $customerIdCurrent = $this->getHelcimDirectService()->getCustomerId($customerCode, $this); 368 if(!$customerIdCurrent){ 369 if($customerIdOld){ 370 $this->getHelcimDirectService()->updateCustomer($customerIdOld, $customerCode, $order, $this); 371 }else{ 372 $this->getHelcimDirectService()->createCustomer($customerCode, $order, $this); 373 } 374 }else{ 375 self::log("cannot update customer code from(".(string)$_POST['customerCode'].") to(".(string)get_current_user_id()."). new customer code is already used"); 376 } 377 } 378 }elseif(get_current_user_id()){ 379 $customerCode = (string)get_current_user_id(); 380 $customerIdCurrent = $this->getHelcimDirectService()->getCustomerId($customerCode, $this); 381 if(!$customerIdCurrent){ 382 $this->getHelcimDirectService()->createCustomer($customerCode, $order, $this); 383 } 384 } 385 386 // process 387 if($this->transactionType === self::TRANSACTION_TYPE_PURCHASE){ 388 $responsePayload = $this->getHelcimDirectService()->processPurchase($order, $this, $customerCode); 389 if (!is_array($responsePayload)) { 390 wc_add_notice('<b>Payment error:</b> Something went wrong please contact the Merchant', 'error'); 391 self::log("ORDER {$order->get_id()} ERROR - {$this->getHelcimDirectService()->getError()}"); 392 $order->add_order_note( 393 "Helcim Payment Failed - {$this->getHelcimDirectService()->getError()}" 394 ); 395 return []; 396 } 397 }elseif($this->transactionType === self::TRANSACTION_TYPE_PREAUTH){ 398 $responsePayload = $this->getHelcimDirectService()->processPreauth($order, $this, $customerCode); 399 if (!is_array($responsePayload)) { 400 wc_add_notice('<b>Payment error:</b> Something went wrong please contact the Merchant', 'error'); 401 self::log("ORDER {$order->get_id()} ERROR - {$this->getHelcimDirectService()->getError()}"); 402 $order->add_order_note( 403 "Helcim Payment Failed - {$this->getHelcimDirectService()->getError()}" 404 ); 405 return []; 406 } 407 } 408 $this->completeOrder( 409 $order, 410 (string)$responsePayload['approvalCode'], 411 (string)$responsePayload['transactionId'], 412 (string)$responsePayload['cardToken'] 413 ); 414 } 325 415 return [ 326 416 'result' => 'success', … … 339 429 { 340 430 if (!$this->getHelcimDirectService() instanceof HelcimDirectService) { 341 $this->setHelcimDirectService(new HelcimDirectService()); 342 } 431 $this->setHelcimDirectService(new HelcimDirectService(new HelcimCurl())); 432 } 433 343 434 $amount = (float)$amount; 344 435 $order = wc_get_order($orderId); 345 $approvalCode = $this->getHelcimDirectService()->processRefund($order, $amount, $this); 436 if(empty($this->apiTokenV2)) { 437 // todo remove whole if condition 438 $approvalCode = $this->getHelcimDirectService()->processRefund($order, $amount, $this); 439 }else{ 440 $approvalCode = $this->getHelcimDirectService()->processRefundV2($order, $amount, $this); 441 } 346 442 if (!is_string($approvalCode)) { 347 443 wc_add_notice("Refund Failed - {$this->getHelcimDirectService()->getError()}", 'error'); … … 718 814 { 719 815 if (!$this->getHelcimDirectService() instanceof HelcimDirectService) { 720 $this->setHelcimDirectService(new HelcimDirectService( ));816 $this->setHelcimDirectService(new HelcimDirectService(new HelcimCurl())); 721 817 } 722 818 $objectXML = $this->getHelcimDirectService()->processVoid($transactionId, $this); -
helcim-commerce-for-woocommerce/trunk/classes/HelcimCurl.php
r2605840 r2946797 3 3 class HelcimCurl 4 4 { 5 private $error;6 private $curlErrorNumber;7 private $curlError;8 private $request;9 private $response;5 private string $error; 6 private int $curlErrorNumber; 7 private string $curlError; 8 private string $request; 9 private string $response; 10 10 11 11 public function __construct() … … 29 29 } 30 30 31 public function curl(array $request, string $url ): ?string31 public function curl(array $request, string $url, array $headers = [], string $method = 'POST'): ?string 32 32 { 33 $this->setRequest(http_build_query($request));34 33 $curlOptions = [ 35 34 CURLOPT_RETURNTRANSFER => 1, … … 37 36 CURLOPT_FRESH_CONNECT => true, 38 37 CURLOPT_HEADER => false, 39 CURLOPT_POST => true,40 38 CURLOPT_POSTFIELDS => $this->getRequest(), 41 39 CURLOPT_TIMEOUT => 60 42 40 ]; 41 if ($method === 'GET') { 42 $this->setRequest(http_build_query($request)); 43 $url .= "?{$this->getRequest()}"; 44 $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; 45 } else { 46 $this->setRequest(json_encode($request)); 47 $curlOptions[CURLOPT_POSTFIELDS] = $this->getRequest(); 48 $curlOptions[CURLOPT_HTTPHEADER][] = 'Content-Type: application/json'; 49 if ($method === 'POST') { 50 $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; 51 } elseif ($method === 'PUT') { 52 $curlOptions[CURLOPT_CUSTOMREQUEST] = $method; 53 } else { 54 WCHelcimGateway::log("Invalid Method: $method"); 55 return null; 56 } 57 } 58 59 if (count($headers) > 0) { 60 foreach ($headers as $h){ 61 $curlOptions[CURLOPT_HTTPHEADER][] = $h; 62 } 63 } 43 64 $curl = curl_init($url); 44 65 curl_setopt_array($curl, $curlOptions); 45 66 $response = curl_exec($curl); 67 68 $info = curl_getinfo($curl); 46 69 $this->setResponse(''); 47 70 $this->setCurlErrorNumber(curl_errno($curl)); … … 50 73 if ($response === false) { 51 74 $this->setError("Communication to Helcim Failed - ({$this->getCurlErrorNumber()}) {$this->getCurlError()}"); 75 WCHelcimGateway::log("$method $url {$info['http_code']} curlError:({$this->getCurlErrorNumber()}) {$this->getCurlError()}"); 52 76 return null; 53 77 } 78 if (!isset($info['http_code']) || (int)$info['http_code'] !== 200){ 79 $responseArray = json_decode($response, true); 80 if(is_array($responseArray) && isset($responseArray['errors'])){ 81 $errors = is_array($responseArray['errors']) 82 ? implode(', ',$responseArray['errors']) : (string)$responseArray['errors']; 83 }else{ 84 $errors = (string)$response; 85 } 86 WCHelcimGateway::log("$method $url {$info['http_code']} error:$errors"); 87 $this->setError("Communication to Helcim Failed - httpCode:{$info['http_code']} response:$response"); 88 return null; 89 } 90 WCHelcimGateway::log("$method $url {$info['http_code']}"); 54 91 $this->setResponse($response); 55 92 return $this->getResponse(); … … 135 172 } 136 173 174 /** 175 * @deprecated please use HelcimApiFactory::genericPaymentPayload 176 * @param WCHelcimGateway $wcHelcimGateway 177 * @return array 178 */ 137 179 public function buildGenericPostData(WCHelcimGateway $wcHelcimGateway): array 138 180 { -
helcim-commerce-for-woocommerce/trunk/classes/HelcimDirectService.php
r2893666 r2946797 3 3 class HelcimDirectService 4 4 { 5 private $helcimCURL; 6 private $error; 7 8 public function __construct() 9 { 5 private HelcimCurl $helcimCURL; 6 private string $error; 7 8 public function __construct(HelcimCurl $helcimCurl) 9 { 10 $this->helcimCURL = $helcimCurl; 10 11 $this->error = ''; 11 12 } 12 13 13 14 /** 15 * @deprecated please use self::processRefundV2 14 16 * @param WC_Order $order 15 17 * @param float $amount 16 18 * @param WCHelcimGateway $helcimGateway 17 * @return false|string19 * @return string|null 18 20 */ 19 21 public function processRefund(WC_Order $order, float $amount, WCHelcimGateway $helcimGateway): ?string 20 22 { 21 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 22 $this->setHelcimCURL(new HelcimCurl()); 23 } 23 24 24 if (!$this->checkOrderForRefund($order, $amount)) { 25 25 $this->setError("Error - {$this->getError()}"); 26 26 return null; 27 27 } 28 $response = $this-> getHelcimCURL()->curl(28 $response = $this->helcimCURL->curl( 29 29 $this->buildRefundPostData($helcimGateway, $order, $amount), 30 30 WCHelcimGateway::API_ENDPOINT 31 31 ); 32 32 if (!is_string($response)) { 33 $this->setError($this-> getHelcimCURL()->getError());34 return null; 35 } 36 $objectXML = $this-> getHelcimCURL()->validXML($response);33 $this->setError($this->helcimCURL->getError()); 34 return null; 35 } 36 $objectXML = $this->helcimCURL->validXML($response); 37 37 if (!$objectXML instanceof SimpleXMLElement) { 38 $this->setError($this-> getHelcimCURL()->getError());38 $this->setError($this->helcimCURL->getError()); 39 39 return null; 40 40 } … … 42 42 } 43 43 44 public function processRefundV2(WC_Order $order, float $amount, WCHelcimGateway $helcimGateway): ?string 45 { 46 47 if (!$this->checkOrderForRefund($order, $amount)) { 48 $this->setError("Error - {$this->getError()}"); 49 return null; 50 } 51 $response = $this->helcimCURL->curl( 52 HelcimApiFactory::buildRefund($order, $amount, $helcimGateway), 53 WCHelcimGateway::API_V2_ENDPOINT.'payment/refund', 54 array_merge( 55 HelcimApiFactory::apiV2Headers($helcimGateway), 56 ['idempotency-key: '.HelcimApiFactory::buildIdempotencyKey(25)] 57 ) 58 ); 59 if (!is_string($response)) { 60 $this->setError($this->helcimCURL->getError()); 61 return null; 62 } 63 $responsePayload = json_decode($response, true); 64 if (!is_array($responsePayload)) { 65 $this->setError($this->helcimCURL->getError()); 66 return null; 67 } 68 return isset($responsePayload['approvalCode']) ? (string)$responsePayload['approvalCode'] : ''; 69 } 70 44 71 private function buildRefundPostData(WCHelcimGateway $helcimGateway, $order, float $amount): array 45 72 { 46 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 47 $this->setHelcimCURL(new HelcimCurl()); 48 } 49 $postData = $this->getHelcimCURL()->buildGenericPostData($helcimGateway); 73 74 $postData = $this->helcimCURL->buildGenericPostData($helcimGateway); 50 75 $postData['transactionType'] = 'refund'; 51 76 $postData['transactionId'] = $order->get_transaction_id(); … … 59 84 public function processVoid(int $transactionId, WCHelcimGateway $wcHelcimGateway): ?SimpleXMLElement 60 85 { 61 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 62 $this->setHelcimCURL(new HelcimCurl()); 63 } 64 $response = $this->getHelcimCURL()->curl( 86 87 $response = $this->helcimCURL->curl( 65 88 $this->buildVoidPostData($wcHelcimGateway, $transactionId), 66 89 WCHelcimGateway::API_ENDPOINT 67 90 ); 68 91 if (!is_string($response)) { 69 $this->setError($this-> getHelcimCURL()->getError());70 return null; 71 } 72 $objectXML = $this-> getHelcimCURL()->validXML($response);92 $this->setError($this->helcimCURL->getError()); 93 return null; 94 } 95 $objectXML = $this->helcimCURL->validXML($response); 73 96 if (!$objectXML instanceof SimpleXMLElement) { 74 $this->setError($this-> getHelcimCURL()->getError());97 $this->setError($this->helcimCURL->getError()); 75 98 return null; 76 99 } … … 80 103 private function buildVoidPostData(WCHelcimGateway $wcHelcimGateway, int $transactionId): array 81 104 { 82 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 83 $this->setHelcimCURL(new HelcimCurl()); 84 } 85 $postData = $this->getHelcimCURL()->buildGenericPostData($wcHelcimGateway); 105 106 $postData = $this->helcimCURL->buildGenericPostData($wcHelcimGateway); 86 107 $postData['transactionType'] = 'void'; 87 108 $postData['transactionId'] = $transactionId; … … 90 111 } 91 112 113 /** 114 * @deprecated please use self::processPurchase or self::processPreauth 115 */ 92 116 public function processPurchasePreauth($order, WCHelcimGateway $wcHelcimGateway): ?SimpleXMLElement 93 117 { 94 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 95 $this->setHelcimCURL(new HelcimCurl()); 96 } 97 $response = $this->getHelcimCURL()->curl( 118 119 $response = $this->helcimCURL->curl( 98 120 $this->buildPurchasePreauthPostData($order, $wcHelcimGateway), 99 121 WCHelcimGateway::API_ENDPOINT 100 122 ); 101 123 if (!is_string($response)) { 102 $this->setError($this-> getHelcimCURL()->getError());103 return null; 104 } 105 $objectXML = $this-> getHelcimCURL()->validXML($response);124 $this->setError($this->helcimCURL->getError()); 125 return null; 126 } 127 $objectXML = $this->helcimCURL->validXML($response); 106 128 if (!$objectXML instanceof SimpleXMLElement) { 107 $this->setError($this-> getHelcimCURL()->getError());129 $this->setError($this->helcimCURL->getError()); 108 130 return null; 109 131 } … … 111 133 } 112 134 135 public function processPurchase(WC_Abstract_Order $order, WCHelcimGateway $wcHelcimGateway, string $customerCode): ?array 136 { 137 $response = $this->helcimCURL->curl( 138 HelcimApiFactory::buildPurchasePreauth($wcHelcimGateway, $order, $customerCode), 139 WCHelcimGateway::API_V2_ENDPOINT.'payment/purchase', 140 array_merge( 141 HelcimApiFactory::apiV2Headers($wcHelcimGateway), 142 ['idempotency-key: '.HelcimApiFactory::buildIdempotencyKey(25)] 143 ) 144 ); 145 //(string)openssl_random_pseudo_bytes(25) 146 if (!is_string($response)) { 147 $this->setError($this->helcimCURL->getError()); 148 return null; 149 } 150 $responsePayload = json_decode($response, true); 151 if (!is_array($responsePayload)) { 152 $this->setError($this->helcimCURL->getError()); 153 return null; 154 } 155 return $responsePayload; 156 } 157 158 public function processPreauth(WC_Abstract_Order $order, WCHelcimGateway $wcHelcimGateway, string $customerCode): ?array 159 { 160 161 $response = $this->helcimCURL->curl( 162 HelcimApiFactory::buildPurchasePreauth($wcHelcimGateway, $order, $customerCode), 163 WCHelcimGateway::API_V2_ENDPOINT.'payment/preauth', 164 array_merge( 165 HelcimApiFactory::apiV2Headers($wcHelcimGateway), 166 ['idempotency-key: '.HelcimApiFactory::buildIdempotencyKey(25)] 167 ) 168 ); 169 if (!is_string($response)) { 170 $this->setError($this->helcimCURL->getError()); 171 return null; 172 } 173 $responsePayload = json_decode($response, true); 174 if (!is_array($responsePayload)) { 175 $this->setError($this->helcimCURL->getError()); 176 return null; 177 } 178 return $responsePayload; 179 } 180 181 /** 182 * @deprecated please use self::buildPurchasePreauthPayload 183 */ 113 184 private function buildPurchasePreauthPostData($order, WCHelcimGateway $wcHelcimGateway): array 114 185 { … … 123 194 } 124 195 } 125 if (!$this->getHelcimCURL() instanceof HelcimCurl) { 126 $this->setHelcimCURL(new HelcimCurl()); 127 } 128 $helcimArgs = $this->getHelcimCURL()->buildGenericPostData($wcHelcimGateway); 196 197 $helcimArgs = $this->helcimCURL->buildGenericPostData($wcHelcimGateway); 129 198 $helcimArgs['transactionType'] = $wcHelcimGateway->getTransactionType(); 130 199 $helcimArgs['terminalId'] = $wcHelcimGateway->getTerminalId(); … … 167 236 foreach ($order->get_items() as $item) { 168 237 $orderItemCounter++; 169 $product = $ order->get_product_from_item($item);238 $product = $item->get_product(); 170 239 $sku = $product->get_sku() ?: 'NoSKU'; 171 240 $helcimArgs['itemSKU' . $orderItemCounter] = $sku; … … 209 278 } 210 279 211 public function getHelcimCURL(): ?HelcimCurl212 {213 return $this->helcimCURL;214 }215 216 public function setHelcimCURL(HelcimCurl $helcimCURL): HelcimDirectService217 {218 $this->helcimCURL = $helcimCURL;219 return $this;220 }221 222 280 private function checkOrderForRefund(WC_Order $order, float $amount): bool 223 281 { … … 247 305 return $this; 248 306 } 307 308 public function getCustomerId(string $customerCode, WCHelcimGateway $helcimGateway): ?int 309 { 310 311 $response = $this->helcimCURL->curl( 312 ['customerCode' => $customerCode], 313 WCHelcimGateway::API_V2_ENDPOINT.'customers/', 314 HelcimApiFactory::apiV2Headers($helcimGateway), 315 'GET' 316 ); 317 if (!is_string($response)) { 318 $this->setError($this->helcimCURL->getError()); 319 return false; 320 } 321 $responsePayload = json_decode($response, true); 322 if(!is_array($responsePayload) || count($responsePayload) === 0){ 323 return 0; 324 } 325 $customer = reset($responsePayload); 326 return isset($customer['id']) ? (int)$customer['id'] : 0; 327 } 328 329 public function updateCustomer(int $customerId, string $customerCode, WC_Abstract_Order $order, WCHelcimGateway $helcimGateway): ?array 330 { 331 332 $response = $this->helcimCURL->curl( 333 [ 334 'customerCode' => $customerCode, 335 'contactName' => $customerCode, 336 'businessName' => $customerCode 337 ], 338 WCHelcimGateway::API_V2_ENDPOINT."customers/$customerId", 339 HelcimApiFactory::apiV2Headers($helcimGateway), 340 'PUT' 341 ); 342 if (!is_string($response)) { 343 $this->setError($this->helcimCURL->getError()); 344 return null; 345 } 346 $responsePayload = json_decode($response, true); 347 if (!is_array($responsePayload)) { 348 $this->setError($this->helcimCURL->getError()); 349 return null; 350 } 351 return $responsePayload; 352 } 353 354 public function createCustomer(string $customerCode, WC_Abstract_Order $order, WCHelcimGateway $wcHelcimGateway): ?array 355 { 356 357 $response = $this->helcimCURL->curl( 358 HelcimApiFactory::buildCustomerCreate($customerCode, $order), 359 WCHelcimGateway::API_V2_ENDPOINT."customers/", 360 HelcimApiFactory::apiV2Headers($wcHelcimGateway) 361 ); 362 if (!is_string($response)) { 363 $this->setError($this->helcimCURL->getError()); 364 return null; 365 } 366 $responsePayload = json_decode($response, true); 367 if (!is_array($responsePayload)) { 368 $this->setError($this->helcimCURL->getError()); 369 return null; 370 } 371 return $responsePayload; 372 } 249 373 } -
helcim-commerce-for-woocommerce/trunk/index.php
r2893666 r2946797 4 4 Plugin URI: https://www.helcim.com/ 5 5 Description: Helcim Commerce for WooCommerce 6 Version: 3.0.76 Version: 4.0.0 7 7 Author: Helcim Inc. 8 8 Author URI: https://www.helcim.com/ -
helcim-commerce-for-woocommerce/trunk/readme.txt
r2893666 r2946797 4 4 Requires at least: 4.7.3 5 5 Tested up to: 6.1.0 6 PHP Version: 7.4 or higher 6 7 7 8 == Description == … … 19 20 20 21 **REQUIREMENTS:** 21 - WooCommerce 2.6.14 to 6.4.122 - WooCommerce 2.6.14 to 7.8.0 22 23 - [Helcim account](https://hub.helcim.com/signup/register/) 23 24 … … 73 74 == Changelog == 74 75 76 = 4.0.0 = 77 * Optimized transaction processing 78 * Tested upto WordPress 6.2 79 * Tested upto woocommerce v7.9 80 81 = 3.0.8 = 82 * Tested upto WordPress 6.2 83 * Tested upto woocommerce v7.8 84 75 85 = 3.0.7 = 76 86 * Tested upto WordPress 6.1 -
helcim-commerce-for-woocommerce/trunk/uninstall.php
r2893666 r2946797 5 5 * Uninstalls Helcim Gateway. 6 6 * 7 * @version 3.0.77 * @version 4.0.0 8 8 * @author Helcim Inc. 9 9 */
Note: See TracChangeset
for help on using the changeset viewer.