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
<?php
defined( 'ABSPATH' ) || exit();
class WC_Braintree_Controller_PayPal extends WC_Braintree_Controller_Frontend {
protected $namespace = 'paypal/';
public function register_routes() {
register_rest_route(
$this->rest_uri(),
'shipping',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'get_shipping_html' ),
'permission_callback' => '__return_true',
)
);
}
public function get_shipping_html( $request ) {
$keys = array( 'first_name', 'last_name', 'address_1', 'address_2', 'city', 'state', 'postcode', 'country' );
foreach ( $keys as $key ) {
$address[ $key ] = $request->get_param( $key );
}
wc_braintree_update_customer_location( $address );
WC()->cart->calculate_totals();
$gateway = WC()->payment_gateways()->payment_gateways()['braintree_paypal'];
$html = wc_braintree_get_template_html(
'paypal-shipping-methods.php',
array(
'gateway' => $gateway,
'packages' => $gateway->get_shipping_packages(),
'chosen_shipping_methods' => WC()->session->get(
'chosen_shipping_methods',
array()
),
)
);
return rest_ensure_response( array( 'html' => $html ) );
}
}