function testGateway_VersionDefaultsToTwo()
 {
     $gateway = new Braintree_Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $encodedClientToken = $gateway->clientToken()->generate();
     $clientToken = base64_decode($encodedClientToken);
     $version = json_decode($clientToken)->version;
     $this->assertEquals(2, $version);
 }
 public function nonceForNewEuropeanBankAccount($options)
 {
     $clientTokenOptions = array('sepaMandateType' => 'business', 'sepaMandateAcceptanceLocation' => 'Rostock, Germany');
     if (array_key_exists("customerId", $options)) {
         $clientTokenOptions["customerId"] = $options["customerId"];
         unset($options["customerId"]);
     }
     $gateway = new Braintree_Gateway($this->_config);
     $clientToken = json_decode(base64_decode($gateway->clientToken()->generate($clientTokenOptions)));
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $response = $this->post('/client_api/v1/sepa_mandates/', json_encode($options));
     if ($response["status"] == 201 || $response["status"] == 202) {
         $body = json_decode($response["body"]);
         return $body->europeBankAccounts[0]->nonce;
     } else {
         throw new Exception(var_dump($response));
     }
 }
 /**
  * possibly_enqueue_scripts
  *
  * Loads front side scripts when viewing cart or checkout pages
  *
  * @since 1.0.0
  */
 function possibly_enqueue_scripts()
 {
     if (!function_exists('is_checkout') || !function_exists('is_cart')) {
         return;
     }
     if (!is_checkout() && !is_cart()) {
         return;
     }
     // Make sure our gateways are enabled before we do anything
     if (!$this->are_our_gateways_enabled()) {
         return;
     }
     // A merchant token is required for everything
     $merchant_access_token = get_option('wc_paypal_braintree_merchant_access_token', '');
     if (empty($merchant_access_token)) {
         return;
     }
     // Always enqueue styles for simplicity's sake (because not all styles are related to JavaScript manipulated elements)
     if (is_checkout()) {
         wp_register_style('paypal_braintree_styles', plugins_url('assets/css/checkout.css', __FILE__));
     } else {
         // cart
         wp_register_style('paypal_braintree_styles', plugins_url('assets/css/cart.css', __FILE__));
     }
     wp_enqueue_style('paypal_braintree_styles');
     // See if we should enqueue any JavaScript at all.
     $should_enqueue_checkout_script = $this->_is_hosted_fields_supported();
     $should_enqueue_cart_script = $this->_is_checkout_from_cart_supported();
     if (!$should_enqueue_cart_script && !$should_enqueue_checkout_script) {
         return;
     }
     $checkout_with_paypal = $this->_get_checkout_with_paypal_params();
     $hosted_fields = $this->_get_hosted_field_params();
     // Sanity check.
     if (!$checkout_with_paypal && !$hosted_fields) {
         return;
     }
     require_once dirname(__FILE__) . '/braintree_sdk/lib/Braintree.php';
     $braintree_gateway = new Braintree_Gateway(array('accessToken' => $merchant_access_token));
     try {
         $client_token = $braintree_gateway->clientToken()->generate();
     } catch (Exception $e) {
         $this->log(__FUNCTION__, 'Error: Unable to generate client token. Reason: ' . $e->getMessage());
         return;
     }
     $paypal_braintree_data = array('token' => $client_token, 'checkoutWithPayPal' => $checkout_with_paypal, 'checkoutWithPayPalContainer' => 'paypal-braintree-button-container', 'hostedFields' => $hosted_fields);
     // Allow things like subscriptions to filter the setup (e.g. to set checkoutWithPayPal singleUse to false)
     $paypal_braintree_data = apply_filters('wc_gateway_paypal_braintree_data', $paypal_braintree_data);
     wp_register_script('paypal_braintree', 'https://js.braintreegateway.com/js/braintree-2.24.1.min.js', array('jquery'));
     if ($should_enqueue_checkout_script) {
         wp_register_script('gateway_paypal_braintree', plugins_url('assets/js/checkout.js', __FILE__), array('jquery', 'paypal_braintree'));
     } else {
         if ($should_enqueue_cart_script) {
             wp_register_script('gateway_paypal_braintree', plugins_url('assets/js/cart.js', __FILE__), array('jquery', 'paypal_braintree', 'jquery-blockui'));
         }
     }
     wp_localize_script('gateway_paypal_braintree', 'paypalBraintreeData', $paypal_braintree_data);
     wp_enqueue_script('gateway_paypal_braintree');
 }