mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 16:15:43 +08:00
Add WC gateway
This commit is contained in:
parent
990c410d75
commit
b173ca1f75
4 changed files with 84 additions and 19 deletions
|
@ -1,18 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* The Google Pay Payment Gateway
|
|
||||||
*
|
|
||||||
* @package WooCommerce\PayPalCommerce\Googlepay
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Googlepay;
|
|
||||||
|
|
||||||
use WC_Payment_Gateway;
|
|
||||||
|
|
||||||
class GooglePayGateway extends WC_Payment_Gateway {
|
|
||||||
const ID = 'ppcp-googlepay';
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -938,5 +938,7 @@ return array(
|
||||||
esc_html( $button_text )
|
esc_html( $button_text )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'googlepay.wc-gateway' => static function ( ContainerInterface $container ): GooglePayGateway {
|
||||||
|
return new GooglePayGateway();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
59
modules/ppcp-googlepay/src/GooglePayGateway.php
Normal file
59
modules/ppcp-googlepay/src/GooglePayGateway.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The Google Pay Payment Gateway
|
||||||
|
*
|
||||||
|
* @package WooCommerce\PayPalCommerce\Googlepay
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\Googlepay;
|
||||||
|
|
||||||
|
use WC_Payment_Gateway;
|
||||||
|
|
||||||
|
class GooglePayGateway extends WC_Payment_Gateway {
|
||||||
|
const ID = 'ppcp-googlepay';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->id = self::ID;
|
||||||
|
|
||||||
|
$this->method_title = __( 'Google Pay', 'woocommerce-paypal-payments' );
|
||||||
|
$this->method_description = __( 'Google Pay', 'woocommerce-paypal-payments' );
|
||||||
|
|
||||||
|
$this->title = $this->get_option( 'title', $this->method_title );
|
||||||
|
$this->description = $this->get_option( 'description', $this->method_description );
|
||||||
|
|
||||||
|
$this->init_form_fields();
|
||||||
|
$this->init_settings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the form fields.
|
||||||
|
*/
|
||||||
|
public function init_form_fields() {
|
||||||
|
$this->form_fields = array(
|
||||||
|
'enabled' => array(
|
||||||
|
'title' => __( 'Enable/Disable', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'label' => __( 'Google Pay', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => 'no',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'Enable/Disable Google Pay payment gateway.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'title' => array(
|
||||||
|
'title' => __( 'Title', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->title,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
'description' => array(
|
||||||
|
'title' => __( 'Description', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'text',
|
||||||
|
'default' => $this->description,
|
||||||
|
'desc_tip' => true,
|
||||||
|
'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce-paypal-payments' ),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\Googlepay;
|
namespace WooCommerce\PayPalCommerce\Googlepay;
|
||||||
|
|
||||||
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
|
||||||
|
use WC_Payment_Gateway;
|
||||||
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
|
||||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
use WooCommerce\PayPalCommerce\Button\Assets\SmartButtonInterface;
|
||||||
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
|
use WooCommerce\PayPalCommerce\Googlepay\Endpoint\UpdatePaymentDataEndpoint;
|
||||||
|
@ -159,6 +160,27 @@ class GooglepayModule implements ModuleInterface {
|
||||||
},
|
},
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
add_filter(
|
||||||
|
'woocommerce_payment_gateways',
|
||||||
|
/**
|
||||||
|
* Param types removed to avoid third-party issues.
|
||||||
|
*
|
||||||
|
* @psalm-suppress MissingClosureParamType
|
||||||
|
*/
|
||||||
|
static function ( $methods ) use ( $c ): array {
|
||||||
|
if ( ! is_array( $methods ) ) {
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
|
||||||
|
$googlepay_gateway = $c->get( 'googlepay.wc-gateway' );
|
||||||
|
assert( $googlepay_gateway instanceof WC_Payment_Gateway );
|
||||||
|
|
||||||
|
$methods[] = $googlepay_gateway;
|
||||||
|
|
||||||
|
return $methods;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue