Sisow_Gateway_Abstract

The Woocommerce Sisow Payment Methods Sisow Gateway Abstract class.

Defined (1)

The class is defined in the following location(s).

/includes/classes/Sisow/Gateway/Abstract.php  
  1. class Sisow_Gateway_Abstract extends WC_Payment_Gateway 
  2. public static function NeedRedirect() { return true; } 
  3.  
  4. public static function getCode() 
  5. throw new Exception('Please implement the getCode method'); 
  6.  
  7. public static function getName() 
  8. throw new Exception('Please implement the getName method'); 
  9.  
  10. public static function getMerchantId() 
  11. return get_option('sisow_merchantid'); 
  12.  
  13. public static function getMerchantKey() 
  14. return get_option('sisow_merchantkey'); 
  15.  
  16. public static function getShopId() 
  17. return get_option('sisow_shopid'); 
  18.  
  19. public static function getWarning() 
  20. return null; 
  21.  
  22. public static function canRefund() 
  23. return true; 
  24.  
  25. public static function addScript() {} 
  26.  
  27. public function getIcon() 
  28. return plugins_url( 'Images/'.$this->getCode().'.png', dirname(__FILE__) ); 
  29.  
  30. public function __construct() 
  31.  
  32. $this->id = $this->getCode(); 
  33. $this->icon = $this->getIcon(); 
  34. $this->has_fields = true; 
  35. $this->method_title = 'Sisow - ' . $this->getName(); 
  36. $this->method_description = sprintf(__('Activate this module to accept %s transactions', 'woocommerce-sisow'), $this->getName()); 
  37.  
  38. if($this->canRefund()) 
  39. $this->supports = array('products', 'refunds'); 
  40. else 
  41. $this->supports = array('products'); 
  42.  
  43. //$this->init_form_fields(); 
  44. $this->init_settings(); 
  45.  
  46. $this->title = $this->get_option('title'); 
  47.  
  48. if($this->get_option('enabled') == 'yes' && !is_admin()) 
  49. $this->addScript(); 
  50.  
  51. add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); 
  52.  
  53. public function init_settings() 
  54. $this->form_fields = array(); 
  55.  
  56. $warning = $this->getWarning(); 
  57.  
  58. if(is_array($warning)) 
  59. $this->form_fields['warning'] = $warning; 
  60. $this->form_fields['enabled'] = array( 
  61. 'title' => __('Enable/Disable', 'woocommerce'),  
  62. 'type' => 'checkbox',  
  63. 'label' => sprintf(__('Enable Sisow %s', 'woocommerce-sisow'), $this->getName()),  
  64. 'default' => 'no' 
  65. ); 
  66.  
  67. $this->form_fields['title'] = array( 
  68. 'title' => __('Title', 'woocommerce'),  
  69. 'type' => 'text',  
  70. 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),  
  71. 'default' => $this->getName(),  
  72. 'desc_tip' => true,  
  73. ); 
  74.  
  75. $this->form_fields['description'] = array( 
  76. 'title' => __('Customer Message', 'woocommerce'),  
  77. 'type' => 'textarea',  
  78. 'default' => sprintf(__('Pay with %s', 'woocommerce-sisow'), $this->getName()),  
  79. ); 
  80.  
  81. $this->form_fields['description_bankaccount'] = array( 
  82. 'title' => __('Description', 'woocommerce'),  
  83. 'type' => 'textarea',  
  84. 'default' => __('Description on the bank account', 'woocommerce-sisow'),  
  85. ); 
  86.  
  87. //if($this->getCode() != 'focum') 
  88. //{ 
  89. $this->form_fields['testmode'] = array(  
  90. 'title' => __('Testmode', 'woocommerce-sisow'),  
  91. 'type' => 'checkbox',  
  92. 'label' => __('Enable testmode', 'woocommerce-sisow'),  
  93. 'default' => 'no',  
  94. ); 
  95. //} 
  96.  
  97. if($this->id == 'overboeking' || $this->id == 'ebill')  
  98. $this->form_fields['days'] = array( 
  99. 'title' => __('Days', 'woocommerce-sisow'),  
  100. 'type' => 'text',  
  101. 'default' => 30,  
  102. ); 
  103.  
  104. $label = $this->id == 'overboeking' ? __('Include paylink', 'woocommerce-sisow') : __('Include bank account details', 'woocommerce-sisow'); 
  105.  
  106. $this->form_fields['including'] = array( 
  107. 'title' => __('Include', 'woocommerce-sisow'),  
  108. 'type' => 'checkbox',  
  109. 'label' => $label,  
  110. 'default' => 'no',  
  111. ); 
  112.  
  113. parent::init_settings(); 
  114.  
  115. public function payment_fields() 
  116. $description = $this->get_option('description'); 
  117. echo $description; 
  118.  
  119. public function process_payment($order_id) 
  120. /** @var $wpdb wpdb The database */ 
  121. global $wpdb; 
  122. global $woocommerce; 
  123. $order = new WC_Order($order_id); 
  124.  
  125. $arg = array(); 
  126. //add Shipping Address 
  127. $arg['ipaddress'] = $_SERVER['REMOTE_ADDR']; 
  128. $arg['shipping_firstname'] = $order->shipping_first_name; 
  129. $arg['shipping_lastname'] = $order->shipping_last_name; 
  130. $arg['shipping_mail'] = $order->billing_email; 
  131. $arg['shipping_company'] = $order->shipping_company; 
  132. $arg['shipping_address1'] = $order->shipping_address_1; 
  133. $arg['shipping_address2'] = $order->shipping_address_2; 
  134. $arg['shipping_zip'] = $order->shipping_postcode; 
  135. $arg['shipping_city'] = $order->shipping_city; 
  136. $arg['shipping_countrycode'] = $order->shipping_country; 
  137. $arg['shipping_phone'] = array_key_exists($this->getCode() . '_phone', $_POST) ? $_POST[$this->getCode() . '_phone'] : $order->billing_phone; 
  138.  
  139. //add Billing Address 
  140. $arg['billing_firstname'] = $order->billing_first_name; 
  141. $arg['billing_lastname'] = $order->billing_last_name; 
  142. $arg['billing_mail'] = $order->billing_email; 
  143. $arg['billing_company'] = $order->billing_company; 
  144. $arg['billing_address1'] = $order->billing_address_1; 
  145. $arg['billing_address2'] = $order->billing_address_2; 
  146. $arg['billing_zip'] = $order->billing_postcode; 
  147. $arg['billing_city'] = $order->billing_city; 
  148. $arg['billing_countrycode'] = $order->billing_country; 
  149. $arg['billing_phone'] = array_key_exists($this->getCode() . '_phone', $_POST) ? $_POST[$this->getCode() . '_phone'] : $order->billing_phone; 
  150.  
  151. //$arg['weight'] = $order->; 
  152. $arg['shipping'] = $order->order_shipping; 
  153. //$arg['handling'] = $order->; 
  154. //$arg['birthdate'] = $order->; 
  155. $arg['tax'] = round($order->order_tax * 100.0); 
  156. $arg['currency'] = $order->order_currency; 
  157.  
  158. //producten 
  159. $item_loop = 0; 
  160. if (sizeof($order->get_items()) > 0) : foreach ($order->get_items() as $item) : 
  161. if ($item['qty']) : 
  162.  
  163. $item_loop++; 
  164.  
  165. $product = $order->get_product_from_item($item); 
  166.  
  167. $_tax = new WC_Tax(); 
  168.  
  169. foreach ($_tax->get_shop_base_rate($product->tax_class) as $line_tax) { 
  170. $tax = $line_tax['rate']; 
  171.  
  172. $arg['product_id_' . $item_loop] = $item['product_id']; 
  173. $arg['product_description_' . $item_loop] = $item['name']; 
  174. $arg['product_quantity_' . $item_loop] = $item['qty']; 
  175. $arg['product_netprice_' . $item_loop] = round($product->get_price_excluding_tax(), 2) * 100; 
  176. $arg['product_total_' . $item_loop] = round($item['line_total'] + $item['line_tax'], 2) * 100; 
  177. $arg['product_nettotal_' . $item_loop] = round($item['line_total'], 2) * 100; 
  178. $arg['product_tax_' . $item_loop] = round($item['line_tax'], 2) * 100; 
  179. $arg['product_taxrate_' . $item_loop] = (!isset($tax)) ? 0 : round($tax, 2) * 100; 
  180. $arg['product_weight_' . $item_loop] = round($product->weight, 2) * 100; 
  181. endif; 
  182. endforeach; 
  183. endif; 
  184.  
  185. //verzendkosten 
  186. if (isset($order->order_shipping)) { 
  187. if ($order->order_shipping > 0) { 
  188. $item_loop++; 
  189. $arg['product_id_' . $item_loop] = 'shipping'; 
  190. $arg['product_description_' . $item_loop] = 'Verzendkosten'; 
  191. $arg['product_quantity_' . $item_loop] = '1'; 
  192. $arg['product_netprice_' . $item_loop] = round($order->order_shipping, 2) * 100; 
  193. $arg['product_total_' . $item_loop] = round($order->order_shipping + $order->order_shipping_tax, 2) * 100; 
  194. $arg['product_nettotal_' . $item_loop] = round($order->order_shipping, 2) * 100; 
  195. $arg['product_tax_' . $item_loop] = round($order->order_shipping_tax, 2) * 100; 
  196. $arg['product_taxrate_' . $item_loop] = round((($arg['product_tax_' . $item_loop] * 100.0) / $arg['product_nettotal_' . $item_loop])) * 100; 
  197.  
  198. //fees 
  199. foreach($order->get_fees() as $fee) 
  200. {  
  201. $item_loop++; 
  202. $arg['product_id_' . $item_loop] = 'fee' . $item_loop; 
  203. $arg['product_description_' . $item_loop] = $fee['name']; 
  204. $arg['product_quantity_' . $item_loop] = '1'; 
  205. $arg['product_netprice_' . $item_loop] = round($fee['line_total'], 2) * 100; 
  206. $arg['product_total_' . $item_loop] = round($fee['line_total'] + $fee['line_tax'], 2) * 100; 
  207. $arg['product_nettotal_' . $item_loop] = round($fee['line_total'], 2) * 100; 
  208. $arg['product_tax_' . $item_loop] = round($fee['line_tax'], 2) * 100; 
  209. $arg['product_taxrate_' . $item_loop] = round((($arg['product_tax_' . $item_loop] * 100.0) / $arg['product_nettotal_' . $item_loop])) * 100; 
  210.  
  211. if($this->get_option('testmode') == 'yes') 
  212. $arg['testmode'] = 'true'; 
  213.  
  214. if($this->get_option('including') == 'yes') 
  215. $arg['including'] = 'true'; 
  216.  
  217. if($this->get_option('days') > 0) 
  218. $arg['days'] = $this->get_option('days'); 
  219.  
  220. if(array_key_exists($this->getCode() . '_bic', $_POST)) 
  221. $arg['bic'] = $_POST[$this->getCode() . '_bic']; 
  222.  
  223. if(array_key_exists($this->getCode() . '_gender', $_POST)) 
  224. $arg['gender'] = $_POST[$this->getCode() . '_gender']; 
  225.  
  226. if(array_key_exists($this->getCode() . '_iban', $_POST)) 
  227. $arg['iban'] = $_POST[$this->getCode() . '_iban']; 
  228.  
  229. if(array_key_exists($this->getCode() . '_birthday_day', $_POST) && array_key_exists($this->getCode() . '_birthday_month', $_POST) && array_key_exists($this->getCode() . '_birthday_year', $_POST)) 
  230. $arg['birthdate'] = $_POST[$this->getCode() . '_birthday_day'] . $_POST[$this->getCode() . '_birthday_month'] . $_POST[$this->getCode() . '_birthday_year']; 
  231.  
  232. $sisow = new Sisow_Helper_Sisow(get_option('sisow_merchantid'), get_option('sisow_merchantkey'), get_option('sisow_shopid')); 
  233. $sisow->purchaseId = ltrim($order->get_order_number(), '#'); 
  234. $description_bankaccount = $this->get_option('description_bankaccount'); 
  235. $sisow->description = (!empty($description_bankaccount) && $description_bankaccount != '') ? rtrim($description_bankaccount) . ' ' . $order->get_order_number() : get_bloginfo('name') . ' ' . $order->get_order_number(); 
  236. $sisow->amount = $order->order_total; 
  237. $sisow->payment = $this->getCode(); 
  238. $sisow->entranceCode = $order_id; 
  239. $sisow->returnUrl = add_query_arg('wc-api', 'Wc_Sisow_Gateway_Return', home_url('/')) . (get_option('sisow_utm_nooverride') == 'yes' ? '&utm_nooverride=1' : ''); 
  240. $sisow->cancelUrl = $order->get_cancel_order_url() . (get_option('sisow_utm_nooverride') == 'yes' ? '&utm_nooverride=1' : ''); 
  241. $sisow->notifyUrl = add_query_arg('wc-api', 'Wc_Sisow_Gateway_Notify', home_url('/')) . (get_option('sisow_utm_nooverride') == 'yes' ? '&utm_nooverride=1' : ''); 
  242. $sisow->callbackUrl = add_query_arg('wc-api', 'Wc_Sisow_Gateway_Notify', home_url('/')) . (get_option('sisow_utm_nooverride') == 'yes' ? '&utm_nooverride=1' : ''); 
  243. if(array_key_exists($this->getCode() . '_issuer', $_POST)) 
  244. $sisow->issuerId = $_POST[$this->getCode() . '_issuer']; 
  245.  
  246. if( ($ex = $sisow->TransactionRequest($arg)) < 0 ) 
  247. if($this->getCode() == 'focum') 
  248. wc_add_notice( 'Betalen met Focum Achteraf Betalen is op dit moment niet mogelijk, betaal anders. (' . $ex . ' ' . $sisow->errorCode . ')', 'error' ); 
  249. else 
  250. wc_add_notice( $ex . ' ' . $sisow->errorCode, 'error' ); 
  251.  
  252. $order->cancel_order('Sisow fout: ' . $ex . ' ' . $sisow->errorCode); 
  253. else 
  254. update_post_meta($order->id, '_trxid', $sisow->trxId); 
  255.  
  256. if($this->getCode() == 'overboeking' || $this->getCode() == 'ebill') 
  257. $order->update_status('on-hold', sprintf(__('%s created', 'woocommerce-sisow'), $this->getName())); 
  258. else if($this->getCode() == 'focum') 
  259. $order->payment_complete($sisow->trxId); 
  260.  
  261. if($this->NeedRedirect()) 
  262. return array('result' => 'success', 'redirect' => $sisow->issuerUrl); 
  263. else 
  264. // Return thankyou redirect 
  265. return array( 
  266. 'result' => 'success',  
  267. 'redirect' => $this->get_return_url( $order ) 
  268. ); 
  269.  
  270. public function process_refund( $order_id, $amount = null, $reason = '' )  
  271. $order = wc_get_order( $order_id ); 
  272. $sisow = new Sisow_Helper_Sisow(get_option('sisow_merchantid'), get_option('sisow_merchantkey'), get_option('sisow_shopid')); 
  273.  
  274. $refundid = $sisow->RefundRequest($order->get_transaction_id(), $amount); 
  275. if($refundid > 0) 
  276. $order->add_order_note( sprintf( __( 'Refunded %s (Sisow amount: %s) - Refund ID: %s', 'woocommerce' ), $amount, $sisow->amount, $refundid ) ); 
  277. return true; 
  278. else  
  279. return false;