| 1 |
<?php |
| 2 |
/* |
| 3 |
Delegate class for talking to Vipps MobilePay, encapsulating all the low-level behaviour and mapping error codes to exceptions |
| 4 |
|
| 5 |
This file is part of the plugin Pay with Vipps and MobilePay for WooCommerce |
| 6 |
Copyright (c) 2019 WP-Hosting AS |
| 7 |
|
| 8 |
MIT License |
| 9 |
|
| 10 |
Copyright (c) 2019 WP-Hosting AS |
| 11 |
|
| 12 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 13 |
of this software and associated documentation files (the "Software"), to deal |
| 14 |
in the Software without restriction, including without limitation the rights |
| 15 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 16 |
copies of the Software, and to permit persons to whom the Software is |
| 17 |
furnished to do so, subject to the following conditions: |
| 18 |
|
| 19 |
The above copyright notice and this permission notice shall be included in all |
| 20 |
copies or substantial portions of the Software. |
| 21 |
|
| 22 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 25 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 26 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 27 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 28 |
SOFTWARE. |
| 29 |
|
| 30 |
*/ |
| 31 |
if ( ! defined('ABSPATH') ) { |
| 32 |
exit; // Exit if accessed directly |
| 33 |
} |
| 34 |
require_once(dirname(__FILE__) . "/VippsApi.class.php"); |
| 35 |
require_once(dirname(__FILE__) . "/WC_Gateway_Vipps.class.php"); |
| 36 |
|
| 37 |
|
| 38 |
class WC_Gateway_VippsCard extends WC_Gateway_Vipps { |
| 39 |
public $form_fields = null; |
| 40 |
public $dev_form_fields = null; |
| 41 |
public $id = 'vipps_card'; |
| 42 |
public $icon = ''; |
| 43 |
public $has_fields = true; |
| 44 |
public $method_title = ''; |
| 45 |
public $title = ''; |
| 46 |
public $method_description = ""; |
| 47 |
|
| 48 |
private static $instance = null; |
| 49 |
// This returns the singleton instance of this class |
| 50 |
public static function instance() { |
| 51 |
if (null === self::$instance) { |
| 52 |
self::$instance = new self(); |
| 53 |
} |
| 54 |
return self::$instance; |
| 55 |
} |
| 56 |
|
| 57 |
public function __construct() { |
| 58 |
$this->testapiurl = 'https://apitest.vipps.no'; |
| 59 |
$this->apiurl = 'https://api.vipps.no'; |
| 60 |
|
| 61 |
$this->method_description = sprintf(__('Offer card payments through %1$s as a payment method', 'woo-vipps'), Vipps::CompanyName()); |
| 62 |
$this->method_title = sprintf(__('Card payments with %1$s','woo-vipps'), Vipps::CompanyName()); |
| 63 |
$this->title = sprintf(__('Card payments with %1$s','woo-vipps'), Vipps::CompanyName()); |
| 64 |
|
| 65 |
$this->icon = plugins_url('img/vmp-logo.png',__FILE__); |
| 66 |
|
| 67 |
$this->init_form_fields(); |
| 68 |
$this->init_settings(); |
| 69 |
|
| 70 |
$this->api = new VippsApi($this); |
| 71 |
$this->supports = array('products','refunds'); |
| 72 |
|
| 73 |
add_action('woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options') ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
public function is_available() { |
| 78 |
if (!WC_Payment_Gateway::is_available()) return false; |
| 79 |
if (!$this->can_be_activated()) return false; |
| 80 |
if ($this->is_test_mode()) return false; // Only available in 'real' mode. IOK 2026-05-27 |
| 81 |
|
| 82 |
$configured = get_option('woo-vipps-configured', false); |
| 83 |
$ok = $configured; |
| 84 |
|
| 85 |
$ok = $ok && $this->payment_method_supports_currency($this->get_payment_method_name(), get_woocommerce_currency()) ; |
| 86 |
|
| 87 |
$ok = apply_filters('woo_vipps_card_payment_is_available', $ok, $this); |
| 88 |
return $ok; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
public function get_icon () { |
| 93 |
$src = plugins_url('img/cclogos.svg',__FILE__); |
| 94 |
return '<img src="' . esc_attr($src) . '" alt="' . $this->get_title() . '">'; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
public function get_option($key, $empty_value = null ) { |
| 99 |
// Our own values |
| 100 |
if (isset($this->form_fields[$key])) return parent::get_option($key, $empty_value); |
| 101 |
|
| 102 |
// Or passthrough to our sister gateway |
| 103 |
$value = WC_Gateway_Vipps::instance()->get_option($key, $empty_value); |
| 104 |
return $value; |
| 105 |
} |
| 106 |
|
| 107 |
// Ensure chosen name gets used in the checkout page IOK 2018-09-12 |
| 108 |
public function get_title() { |
| 109 |
$title = sprintf(__('Card payment with %1$s', 'woo-vipps'), $this->get_payment_method_name()); |
| 110 |
return apply_filters('woo_vipps_card_payment_method_title', $title); |
| 111 |
} |
| 112 |
|
| 113 |
public function init_form_fields() { |
| 114 |
$this->form_fields = array( |
| 115 |
'enabled' => array( |
| 116 |
'title' => __( 'Enable/Disable', 'woocommerce' ), |
| 117 |
'label' => sprintf(__('Enable card payments with %1$s', 'woo-vipps'), Vipps::CompanyName()), |
| 118 |
'type' => 'checkbox', |
| 119 |
'description' => '', |
| 120 |
'default' => 'no' |
| 121 |
), |
| 122 |
'description' => array( |
| 123 |
'title' => __('Description', 'woocommerce'), |
| 124 |
'type' => 'textarea', |
| 125 |
'description' => __('This controls the description which the user sees during checkout.', 'woocommerce'), |
| 126 |
/* translators: company name */ |
| 127 |
'default' => sprintf(__('Pay with credit or debit card through %1$s', 'woo-vipps'), Vipps::CompanyName()), |
| 128 |
), |
| 129 |
|
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
public function process_admin_options () { |
| 134 |
// Handle options updates in the default class (not in _Vipps) |
| 135 |
$saved = WC_Payment_Gateway::process_admin_options(); |
| 136 |
return; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
|