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
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Braintree_Payment_Gateway' ) ) {
return;
}
class WC_Braintree_Venmo_Payment_Gateway extends WC_Braintree_Payment_Gateway {
public function __construct() {
$this->id = 'braintree_venmo';
$this->template = 'venmo.php';
$this->token_type = 'Venmo';
$this->method_title = __( 'Braintree Venmo Gateway', 'woo-payment-gateway' );
$this->tab_title = __( 'Venmo', 'woo-payment-gateway' );
$this->method_description = __( 'Gateway that integrates Venmo with your Braintree account.', 'woo-payment-gateway' );
parent::__construct();
$this->icon = braintree()->assets_path() . 'img/payment-methods/' . $this->get_option( 'icon' ) . '.svg';
}
public function add_hooks() {
add_filter( 'woocommerce_payment_methods_list_item', array( $this, 'payment_methods_list_item' ), 10, 2 );
parent::add_hooks();
}
public function enqueue_checkout_scripts( $scripts ) {
$scripts->enqueue_script(
'venmo',
$scripts->assets_url( 'js/frontend/venmo.js' ),
array(
$scripts->get_handle( 'client-manager' ),
$scripts->get_handle( 'venmo-v3' ),
$scripts->get_handle( 'data-collector-v3' ),
)
);
$scripts->localize_script( 'venmo', $this->localize_venmo_params() );
}
public function localize_venmo_params() {
return array_merge(
$this->get_localized_standard_params(),
array(
'html' => array( 'button' => wc_braintree_get_template_html( 'venmo-button.php' ) ),
)
);
}
public function payment_methods_list_item( $item, $payment_token ) {
if ( 'Braintree_Venmo' !== $payment_token->get_type() ) {
return $item;
}
$item['method']['brand'] = $payment_token->get_payment_method_title( $this->get_option( 'method_format' ) );
$item['expires'] = __( 'N/A', 'woo-payment-gateway' );
$item['method_type'] = $payment_token->get_method_type();
$item['wc_braintree_method'] = true;
return $item;
}
public function get_payment_method_from_transaction( $transaction ) {
return $transaction->venmoAccountDetails;
}
public function has_enqueued_scripts( $scripts, $context = 'checkout' ) {
switch ( $context ) {
case 'checkout':
return wp_script_is( $scripts->get_handle( 'venmo' ) );
}
}
}