| 1 |
<?php |
| 2 |
/** |
| 3 |
* Vipps payment gateway implementation for Gutenberg Blocks |
| 4 |
* |
| 5 |
* @package WooCommerce/Blocks |
| 6 |
* @since 3.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace Automattic\WooCommerce\Blocks\Payments\Integrations; |
| 10 |
|
| 11 |
final class Vipps extends AbstractPaymentMethodType { |
| 12 |
private $localized=0; |
| 13 |
protected $name = 'vipps'; |
| 14 |
protected $payment_method_name = "Vipps"; |
| 15 |
|
| 16 |
public function initialize() { |
| 17 |
$this->settings = get_option( 'woocommerce_vipps_settings', [] ); |
| 18 |
$this->payment_method_name = \WC_Gateway_Vipps::instance()->get_payment_method_name(); |
| 19 |
} |
| 20 |
|
| 21 |
// Register this payment method IOK 2020-08-10 |
| 22 |
public static function register() { |
| 23 |
add_action( 'woocommerce_blocks_payment_method_type_registration', |
| 24 |
function ($registry) { |
| 25 |
$registry->register(new static()); |
| 26 |
}); |
| 27 |
} |
| 28 |
|
| 29 |
public function is_active() { |
| 30 |
return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN ); |
| 31 |
} |
| 32 |
public function get_payment_method_script_handles() { |
| 33 |
|
| 34 |
$version = filemtime(dirname(__FILE__) . "/js/wc-payment-method-vipps.js"); |
| 35 |
$path = plugins_url('js/wc-payment-method-vipps.js', __FILE__); |
| 36 |
$handle = 'wc-payment-method-vipps'; |
| 37 |
$dependencies = array('wp-hooks', 'vipps-gw'); |
| 38 |
|
| 39 |
wp_register_script($handle, $path, $dependencies,$version,true); |
| 40 |
|
| 41 |
|
| 42 |
// Will not use wp_set_script_translations yet, it seems to be not fully compatible with Loco Translate etc. Instead use |
| 43 |
// old-fashioned localize-script IOK 2020-08-11 |
| 44 |
// wp_set_script_translations( 'wc-payment-method-vipps', 'woo-vipps' ); |
| 45 |
// VippsLocale is localized for vipps-gw instead of this, as it seems it does no longer work to do localize-script at this point. |
| 46 |
// IOK 2022-12-13 |
| 47 |
|
| 48 |
return [ 'wc-payment-method-vipps' ]; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_express_checkout_button () { |
| 52 |
$button = \Vipps::instance()->express_checkout_button_shortcode(); |
| 53 |
return $button; |
| 54 |
} |
| 55 |
public function show_express_checkout_button () { |
| 56 |
$gw = \Vipps::instance()->gateway(); |
| 57 |
if (!$gw->cart_supports_express_checkout()) return false; |
| 58 |
return $gw->show_express_checkout(); |
| 59 |
} |
| 60 |
|
| 61 |
public function get_payment_method_data() { |
| 62 |
|
| 63 |
$logo = ($this->payment_method_name == "Vipps") ? plugins_url('../../img/vipps-mark.svg', __FILE__) : plugins_url('../../img/mobilepay-mark.png', __FILE__); |
| 64 |
|
| 65 |
return [ |
| 66 |
'title' => $this->payment_method_name, |
| 67 |
'description' => $this->get_setting( 'description' ), |
| 68 |
'iconsrc' => apply_filters('woo_vipps_block_logo_url', $logo), |
| 69 |
'show_express_checkout' => $this->show_express_checkout_button(), |
| 70 |
'expressbutton' => $this->get_express_checkout_button() |
| 71 |
]; |
| 72 |
} |
| 73 |
} |
| 74 |
|