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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
<?php
defined( 'ABSPATH' ) || exit();
use PaymentPlugins\WC_Braintree_Constants as Constants;
class WC_Braintree_Field_Manager {
private static $_output_checkout_fields = false;
public static function init() {
add_action( 'init', array( __CLASS__, 'action_init' ) );
add_action( 'woocommerce_review_order_before_payment', array( __CLASS__, 'output_checkout_fields' ) );
add_action( 'woocommerce_checkout_update_order_review', array( __CLASS__, 'checkout_update_order_review' ) );
add_action( 'before_woocommerce_pay', array( __CLASS__, 'change_payment_request' ) );
add_action( 'woocommerce_before_add_to_cart_form', array( __CLASS__, 'before_add_to_cart' ) );
add_action( 'woocommerce_widget_shopping_cart_buttons', array( __CLASS__, 'mini_cart_buttons' ), 5 );
}
public static function action_init() {
add_action( 'woocommerce_proceed_to_checkout', 'wc_braintree_cart_checkout_template', apply_filters( 'wc_braintree_cart_buttons_priority', 30 ) );
}
public static function after_template_part( $template_name, $template_path ) {
if ( empty( $template_path ) && $template_name == 'checkout/review-order.php' && is_checkout() && ! self::$_output_checkout_fields ) {
self::output_checkout_fields();
}
}
public static function output_checkout_fields() {
do_action( 'wc_braintree_output_checkout_fields' );
if ( ! WC()->cart->needs_payment() ) {
wp_add_inline_script( braintree()->scripts()->get_handle( 'client-manager' ),
'var wc_braintree_cart_needs_payment = false', 'before' );
}
self::$_output_checkout_fields = true;
}
public static function output_cart_fields() {
}
public static function checkout_update_order_review() {
if ( is_ajax() ) {
WC()->payment_gateways();
}
}
public static function change_payment_request() {
if ( wcs_braintree_active() && WC_Subscriptions_Change_Payment_Gateway::$is_request_to_change_payment ) {
$subscription = wcs_get_subscription( absint( $_GET['change_payment_method'] ) );
do_action( 'wc_braintree_output_change_payment_method_fields' );
}
}
public static function change_braintree_payment_method( $subscription ) {
}
public static function output_subscription_pay_fields( $order ) {
}
public static function before_add_to_cart() {
global $product;
$position = $product->get_meta( Constants::BUTTON_POSITION );
if ( empty( $position ) ) {
$position = 'bottom';
}
if ( 'bottom' == $position ) {
$action = 'woocommerce_after_add_to_cart_button';
} else {
$action = 'woocommerce_before_add_to_cart_button';
}
add_action( $action, array( __CLASS__, 'output_product_checkout_fields' ) );
}
public static function output_product_checkout_fields() {
global $product;
$gateways = array();
$ordering = $product->get_meta( Constants::PRODUCT_GATEWAY_ORDER );
$ordering = ! $ordering ? array() : $ordering;
foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $id => $gateway ) {
if ( $gateway->supports( 'wc_braintree_product_checkout' ) && ! $product->is_type( 'external' ) ) {
$option = new WC_Braintree_Product_Gateway_Option( $product, $gateway );
if ( $option->enabled() ) {
$gateway->set_product_gateway_option( $option );
if ( isset( $ordering[ $gateway->id ] ) ) {
$gateways[ $ordering[ $gateway->id ] ] = $gateway;
} else {
$gateways[] = $gateway;
}
}
}
}
if ( count( apply_filters( 'wc_braintree_product_payment_gateways', $gateways ) ) > 0 ) {
ksort( $gateways );
wc_braintree_get_template( 'product/payment.php', array( 'gateways' => $gateways ) );
do_action( 'wc_braintree_output_product_checkout_fields' );
}
}
public static function mini_cart_buttons() {
$gateways = array();
foreach ( WC()->payment_gateways()->get_available_payment_gateways() as $id => $gateway ) {
if ( $gateway instanceof WC_Braintree_Payment_Gateway && $gateway->supports( 'wc_braintree_mini_cart' ) && $gateway->mini_cart_enabled() ) {
$gateways[ $id ] = $gateway;
}
}
if ( $gateways ) {
wc_braintree_get_template( 'mini-cart/payment-methods.php', array( 'gateways' => $gateways ) );
}
}
public static function pay_order_fields() {
}
public static function output_needs_shipping( $needs_shipping ) {
}
public static function get_cart_total() {
$total = WC()->cart->total;
return $total;
}
public static function required_checkout_fields( $checkout ) {
}
public static function recurring_cart_total( $total ) {
}
}
if ( ! is_admin() ) {
WC_Braintree_Field_Manager::init();
}