1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
return;
}
class WC_Payment_Gateway_Stripe_WeChat extends WC_Payment_Gateway_Stripe_Local_Payment {
use WC_Stripe_Local_Payment_Charge_Trait;
public function __construct() {
$this->local_payment_type = 'wechat';
$this->currencies = array( 'AUD', 'CAD', 'CHF', 'CNY', 'DKK', 'EUR', 'GBP', 'HKD', 'JPY', 'NOK', 'SEK', 'SGD', 'USD' );
$this->id = 'stripe_wechat';
$this->tab_title = __( 'WeChat', 'woo-stripe-payment' );
$this->template_name = 'local-payment.php';
$this->token_type = 'Stripe_Local';
$this->method_title = __( 'WeChat', 'woo-stripe-payment' );
$this->method_description = __( 'WeChat gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
$this->icon = stripe_wc()->assets_url( 'img/wechat.svg' );
parent::__construct();
}
public function init_form_fields() {
parent::init_form_fields();
$this->form_fields['allowed_countries']['default'] = 'all';
}
public function get_local_payment_settings() {
return array_merge( parent::get_local_payment_settings(), array(
'qr_size' => array(
'type' => 'input',
'title' => __( 'QRCode Size', 'woo-stripe-payment' ),
'default' => '128',
'desc_tip' => true,
'description' => __( 'This option controls the width and height in pixels of the QRCode.', 'woo-stripe-payment' ),
'sanitize_callback' => function ( $value ) {
if ( ! is_numeric( $value ) ) {
$value = 128;
}
return $value;
}
)
) );
}
public function get_source_redirect_url( $source, $order ) {
if ( wc_stripe_mode() == 'live' ) {
return sprintf(
'#qrcode=%s',
base64_encode(
wp_json_encode(
array(
'code' => $source->wechat->qr_code_url,
'redirect' => $this->get_return_url( $order ),
)
)
)
);
}
return $source->wechat->qr_code_url;
}
public function get_localized_params() {
$data = parent::get_localized_params();
$data['qr_script'] = sprintf( stripe_wc()->scripts()->assets_url( 'js/frontend/qrcode.js?ver=%s' ), stripe_wc()->version );
$data['qr_message'] = __( 'Scan the QR code using your WeChat app. Once scanned click the Place Order button.', 'woo-stripe-payment' );
$data['qr_size'] = $this->get_option( 'qr_size', 128 );
return $data;
}
}