| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Gateway\Blocks; |
| 4 |
|
| 5 |
class PayplugApplePay extends PayplugGenericBlock |
| 6 |
{ |
| 7 |
|
| 8 |
/** |
| 9 |
* Payment method name/id/slug. |
| 10 |
* |
| 11 |
* @var string |
| 12 |
*/ |
| 13 |
protected $name = "apple_pay"; |
| 14 |
|
| 15 |
/** |
| 16 |
* Returns an associative array of data to be exposed for the payment method's client side. |
| 17 |
*/ |
| 18 |
public function get_payment_method_data() { |
| 19 |
$data = parent::get_payment_method_data(); |
| 20 |
$data['icon'] = [ |
| 21 |
"src" => esc_url(PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/images/checkout/' . $this->gateway->image), |
| 22 |
'icon_alt' => $data['name'], |
| 23 |
]; |
| 24 |
|
| 25 |
$data['payplug_locale'] = get_locale(); |
| 26 |
$data['payplug_countryCode'] = WC()->customer !== null ? WC()->customer->get_billing_country() : "FR"; |
| 27 |
$data['payplug_currencyCode'] = get_woocommerce_currency(); |
| 28 |
$data['payplug_apple_pay_domain'] = $_SERVER['HTTP_HOST']; |
| 29 |
$data['ajax_url_applepay_update_payment'] = \WC_AJAX::get_endpoint('applepay_update_payment'); |
| 30 |
$data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent'); |
| 31 |
|
| 32 |
|
| 33 |
return $data; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Returns an array of scripts/handles to be registered for this payment method. |
| 38 |
* |
| 39 |
* @return array |
| 40 |
*/ |
| 41 |
public function get_payment_method_script_handles() { |
| 42 |
|
| 43 |
wp_register_script( |
| 44 |
'apple-pay-sdk', |
| 45 |
'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js', |
| 46 |
array(), |
| 47 |
'1.latest', |
| 48 |
true |
| 49 |
); |
| 50 |
|
| 51 |
wp_enqueue_style('payplug-apple-pay', PAYPLUG_GATEWAY_PLUGIN_URL . 'assets/css/payplug-apple-pay.css', [], PAYPLUG_GATEWAY_VERSION); |
| 52 |
wp_enqueue_script( 'apple-pay-sdk' ); |
| 53 |
|
| 54 |
return parent::get_payment_method_script_handles(); |
| 55 |
} |
| 56 |
|
| 57 |
public function is_active() |
| 58 |
{ |
| 59 |
if (class_exists('WC_Blocks_Utils')) { |
| 60 |
if (\WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' )) { |
| 61 |
|
| 62 |
if( $this->gateway->checkApplePay() && $this->gateway->checkDeviceComptability() && $this->gateway->isSSL() ){ |
| 63 |
return true; |
| 64 |
} |
| 65 |
|
| 66 |
return false; |
| 67 |
|
| 68 |
|
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
} |
| 74 |
|