swissChili | f0cbdc3 | 2023-01-05 17:21:38 -0500 | [diff] [blame] | 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Boleto Payment Method class extending UPE base class |
| 8 | */ |
| 9 | class WC_Stripe_UPE_Payment_Method_Boleto extends WC_Stripe_UPE_Payment_Method { |
| 10 | |
| 11 | const STRIPE_ID = 'boleto'; |
| 12 | |
| 13 | const LPM_GATEWAY_CLASS = WC_Gateway_Stripe_Boleto::class; |
| 14 | |
| 15 | /** |
| 16 | * Constructor for Boleto payment method |
| 17 | * |
| 18 | * @since 5.8.0 |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | parent::__construct(); |
| 22 | $this->stripe_id = self::STRIPE_ID; |
| 23 | $this->can_refund = false; |
| 24 | $this->title = 'Pay with Boleto'; |
| 25 | $this->is_reusable = false; |
| 26 | $this->supported_currencies = [ 'BRL' ]; |
| 27 | $this->supported_countries = [ 'BR' ]; |
| 28 | $this->label = __( 'Boleto', 'woocommerce-gateway-stripe' ); |
| 29 | $this->description = __( |
| 30 | 'Boleto is an official payment method in Brazil. Customers receive a voucher that can be paid at authorized agencies or banks, ATMs, or online bank portals.', |
| 31 | 'woocommerce-gateway-stripe' |
| 32 | ); |
| 33 | |
| 34 | add_filter( 'wc_stripe_allowed_payment_processing_statuses', [ $this, 'add_allowed_payment_processing_statuses' ], 10, 2 ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Adds on-hold as accepted status during webhook handling on orders paid with Boleto |
| 39 | * |
| 40 | * @param $allowed_statuses |
| 41 | * @param $order |
| 42 | * |
| 43 | * @return mixed |
| 44 | */ |
| 45 | public function add_allowed_payment_processing_statuses( $allowed_statuses, $order ) { |
| 46 | if ( 'boleto' === $order->get_meta( '_stripe_upe_payment_type' ) && ! in_array( 'on-hold', $allowed_statuses ) ) { |
| 47 | $allowed_statuses[] = 'on-hold'; |
| 48 | } |
| 49 | |
| 50 | return $allowed_statuses; |
| 51 | } |
| 52 | } |