| 1 |
<?php |
| 2 |
|
| 3 |
namespace Payplug\PayplugWoocommerce\Gateway\Blocks; |
| 4 |
|
| 5 |
class PayplugAmex extends PayplugGenericBlock |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Payment method name/id/slug. |
| 9 |
* |
| 10 |
* @var string |
| 11 |
*/ |
| 12 |
protected $name = 'american_express'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Returns an associative array of data to be exposed for the payment method's client side. |
| 16 |
*/ |
| 17 |
public function get_payment_method_data() |
| 18 |
{ |
| 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 |
$configuration = $this->get_service('configuration'); |
| 26 |
$embedded_mode = $configuration->get_option('payment_methods.configuration.payplug.embedded_mode'); |
| 27 |
if ('popup' == $embedded_mode) { |
| 28 |
$data['payment_method'] = $this->get_name(); |
| 29 |
$data['popup'] = true; |
| 30 |
$data['payplug_create_intent_payment'] = \WC_AJAX::get_endpoint('payplug_create_intent'); |
| 31 |
$data['payplug_create_order'] = \WC_AJAX::get_endpoint('payplug_create_order'); |
| 32 |
$data['wp_nonce'] = wp_create_nonce('woocommerce-process_checkout'); |
| 33 |
} |
| 34 |
|
| 35 |
return $data; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Returns an array of scripts/handles to be registered for this payment method. |
| 40 |
* |
| 41 |
* @return array |
| 42 |
*/ |
| 43 |
public function get_payment_method_script_handles() |
| 44 |
{ |
| 45 |
$configuration = $this->get_service('configuration'); |
| 46 |
$embedded_mode = $configuration->get_option('payment_methods.configuration.payplug.embedded_mode'); |
| 47 |
if ('popup' == $embedded_mode) { |
| 48 |
$this->popup_scripts(); |
| 49 |
} |
| 50 |
|
| 51 |
return parent::get_payment_method_script_handles(); |
| 52 |
} |
| 53 |
|
| 54 |
private function popup_scripts(): void |
| 55 |
{ |
| 56 |
wp_register_script('payplug', 'https://api.payplug.com/js/1/form.latest.js', [], null, true); |
| 57 |
wp_enqueue_script('payplug'); |
| 58 |
} |
| 59 |
} |
| 60 |
|