blob: 1c8bc2b19da4e06edff016350bdabd205faa02fc [file] [log] [blame]
swissChilif0cbdc32023-01-05 17:21:38 -05001<?php
2if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4}
5
6/**
7 * Class that handles OXXO payment method.
8 *
9 * @extends WC_Gateway_Stripe
10 *
11 * @since 5.8.0
12 */
13class WC_Gateway_Stripe_Oxxo extends WC_Stripe_Payment_Gateway_Voucher {
14
15 /**
16 * ID used by UPE
17 *
18 * @var string
19 */
20 const ID = 'stripe_boleto';
21
22 /**
23 * ID used by WooCommerce to identify the payment method
24 *
25 * @var string
26 */
27 public $id = 'stripe_oxxo';
28
29 /**
30 * ID used by stripe
31 */
32 protected $stripe_id = 'oxxo';
33
34 /**
35 * List of accepted currencies
36 *
37 * @var array
38 */
39 protected $supported_currencies = [ 'MXN' ];
40
41 /**
42 * List of accepted countries
43 */
44 protected $supported_countries = [ 'MX' ];
45
46 /**
47 * Constructor
48 *
49 * @since 5.8.0
50 */
51 public function __construct() {
52 $this->method_title = __( 'Stripe OXXO', 'woocommerce-gateway-stripe' );
53 parent::__construct();
54
55 add_filter( 'wc_stripe_allowed_payment_processing_statuses', [ $this, 'add_allowed_payment_processing_statuses' ], 10, 2 );
56 }
57
58 /**
59 * Adds on-hold as accepted status during webhook handling on orders paid with voucher
60 *
61 * @param $allowed_statuses
62 * @param $order
63 *
64 * @return mixed
65 */
66 public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) {
67 if ( $this->stripe_id === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( 'on-hold', $allowed_statuses ) ) {
68 $allowed_statuses[] = 'on-hold';
69 }
70
71 return $allowed_statuses;
72 }
73
74 /**
75 * Payment form on checkout page
76 *
77 * @since 5.8.0
78 */
79 public function payment_fields() {
80 $description = $this->get_description();
81 apply_filters( 'wc_stripe_description', wpautop( wp_kses_post( $description ) ), $this->id )
82 ?>
83 <div class="stripe-source-errors" role="alert"></div>
84
85 <div id="stripe-boleto-payment-data"><?php echo $description; ?></div>
86 <?php
87 }
88
89 /**
90 * Validates the minimum and maximum amount. Throws exception when out of range value is added
91 *
92 * @since 5.8.0
93 *
94 * @param $amount
95 *
96 * @throws WC_Stripe_Exception
97 */
98 protected function validate_amount_limits( $amount ) {
99
100 if ( $amount < 10.00 ) {
101 /* translators: 1) amount (including currency symbol) */
102 throw new WC_Stripe_Exception( sprintf( __( 'Sorry, the minimum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( 10.0 ) ) );
103 } elseif ( $amount > 10000.00 ) {
104 /* translators: 1) amount (including currency symbol) */
105 throw new WC_Stripe_Exception( sprintf( __( 'Sorry, the maximum allowed order total is %1$s to use this payment method.', 'woocommerce-gateway-stripe' ), wc_price( 10000.00 ) ) );
106 }
107 }
108
109 /**
110 * Gather the data necessary to confirm the payment via javascript
111 * Override this when extending the class
112 *
113 * @param WC_Order $order
114 *
115 * @return array
116 */
117 protected function get_confirm_payment_data( $order ) {
118 return [
119 'payment_method' => [
120 'billing_details' => [
121 'name' => $order->get_formatted_billing_full_name(),
122 'email' => $order->get_billing_email(),
123 ],
124 ],
125 ];
126 }
127}