| 1 |
<?php |
| 2 |
namespace WPFunnels\Gateway; |
| 3 |
|
| 4 |
use WPFunnels\Wpfnl_functions; |
| 5 |
|
| 6 |
/** |
| 7 |
* @author [WPFunnels Team] |
| 8 |
* @email [[email protected]] |
| 9 |
* @create date 2022-06-09 16:28:09 |
| 10 |
* @modify date 2022-06-09 16:28:09 |
| 11 |
* @desc [Supporting Direct Bank Transfer with WPFunnels one-click offer] |
| 12 |
*/ |
| 13 |
|
| 14 |
class Wpfnl_Gateway_Bacs { |
| 15 |
|
| 16 |
/** |
| 17 |
* @var string |
| 18 |
* @since 1.6.7 |
| 19 |
*/ |
| 20 |
public $key = 'bacs'; |
| 21 |
|
| 22 |
/** |
| 23 |
* @var bool |
| 24 |
* @since 1.6.7 |
| 25 |
*/ |
| 26 |
public $refund_support; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var bool |
| 30 |
* @since 1.6.7 |
| 31 |
*/ |
| 32 |
private $token = false; |
| 33 |
|
| 34 |
|
| 35 |
function __construct() |
| 36 |
{ |
| 37 |
$this->token = true; |
| 38 |
add_filter('woocommerce_bacs_process_payment_order_status', array($this, 'maybe_setup_offer_for_bacs'), 10, 2); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
/** |
| 43 |
* Try and get the payment token saved by the gateway |
| 44 |
* |
| 45 |
* @param WC_Order $order |
| 46 |
* |
| 47 |
* @return true |
| 48 |
* @since 1.6.7 |
| 49 |
*/ |
| 50 |
public function has_token( $order ) { |
| 51 |
return $this->token; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Possibly sets a custom order status for BACS payment method based on funnel settings. |
| 56 |
* |
| 57 |
* If the 'offer_orders' setting is set to 'main-order' and a valid funnel ID exists |
| 58 |
* for the given order, the order status will be overridden with 'wc-wpfnl-main-order'. |
| 59 |
* Otherwise, the original order status will be returned unchanged. |
| 60 |
* |
| 61 |
* @param string $order_status The current order status. |
| 62 |
* @param WC_Order $order The WooCommerce order object. |
| 63 |
* |
| 64 |
* @return string The modified or original order status. |
| 65 |
* @since 2.5.10 |
| 66 |
*/ |
| 67 |
public function maybe_setup_offer_for_bacs($order_status, $order){ |
| 68 |
$funnel_id = Wpfnl_functions::get_funnel_id_from_order($order->get_id()); |
| 69 |
$offer_settings = Wpfnl_functions::get_offer_settings(); |
| 70 |
if ($offer_settings['offer_orders'] == 'main-order' && $funnel_id) { |
| 71 |
return 'wc-wpfnl-main-order'; |
| 72 |
} |
| 73 |
|
| 74 |
return $order_status; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* Process payment for one-click offer product |
| 80 |
* |
| 81 |
* @param mixed $order |
| 82 |
* |
| 83 |
* @return array |
| 84 |
* @since 1.6.7 |
| 85 |
*/ |
| 86 |
public function process_payment( $order ) { |
| 87 |
|
| 88 |
if($this->key === $order->get_payment_method() && $this->has_token($order)){ |
| 89 |
return array( |
| 90 |
'is_success' => true, |
| 91 |
'message' => 'Success' |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
} |