BankTransfer.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\PaymentMethods\BankTransfer; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Controllers\CheckoutResponse; |
| 6 | use ProfilePress\Core\Membership\Models\Order\OrderEntity; |
| 7 | use ProfilePress\Core\Membership\PaymentMethods\AbstractPaymentMethod; |
| 8 | |
| 9 | class BankTransfer extends AbstractPaymentMethod |
| 10 | { |
| 11 | public function __construct() |
| 12 | { |
| 13 | parent::__construct(); |
| 14 | |
| 15 | $this->id = 'bank_transfer'; |
| 16 | $this->title = esc_html__('Direct bank transfer', 'wp-user-avatar'); |
| 17 | $this->description = esc_html__('Make your payment to our bank account. Please use your Order ID as the payment reference. Your order will only be completed once the funds have cleared in our account.', 'wp-user-avatar'); |
| 18 | |
| 19 | $this->method_title = esc_html__('Direct bank transfer', 'wp-user-avatar'); |
| 20 | $this->method_description = esc_html__('Take payments in person via BACS. More commonly known as direct bank/wire transfer.', 'wp-user-avatar'); |
| 21 | |
| 22 | $this->icon = ''; |
| 23 | |
| 24 | $this->supports = [self::SUBSCRIPTIONS]; |
| 25 | |
| 26 | add_action('ppress_myaccount_view_order_before_order_details_table', [$this, 'frontend_bank_account_details']); |
| 27 | } |
| 28 | |
| 29 | protected function is_billing_fields_removed() |
| 30 | { |
| 31 | return $this->get_value('remove_billing_fields') == 'true'; |
| 32 | } |
| 33 | |
| 34 | public function admin_settings() |
| 35 | { |
| 36 | $settings = parent::admin_settings(); |
| 37 | |
| 38 | $settings['description']['type'] = 'textarea'; |
| 39 | |
| 40 | $default_bank_details = <<<BANK |
| 41 | <p>Below are our bank details.</p> |
| 42 | <ul> |
| 43 | <li>Account holder:</li> |
| 44 | <li>IBAN:</li> |
| 45 | <li>BIC/SWIFT:</li> |
| 46 | </ul> |
| 47 | <p>Please initiate the bank transfer to complete your order. Use your order number as the payment reference.</p> |
| 48 | BANK; |
| 49 | |
| 50 | $settings['account_details'] = [ |
| 51 | 'label' => esc_html__('Bank Account details', 'wp-user-avatar'), |
| 52 | 'type' => 'wp_editor', |
| 53 | 'value' => $default_bank_details, |
| 54 | 'description' => esc_html__('These account details will be displayed on the order confirmation page.', 'wp-user-avatar') |
| 55 | ]; |
| 56 | |
| 57 | $settings['remove_billing_fields'] = [ |
| 58 | 'label' => esc_html__('Remove Billing Address', 'wp-user-avatar'), |
| 59 | 'type' => 'checkbox', |
| 60 | 'checkbox_label' => esc_html__('Check to remove billing address fields from the checkout page.', 'wp-user-avatar'), |
| 61 | 'description' => esc_html__('If you do not want the billing address fields displayed on the checkout page, use this setting to remove it.', 'wp-user-avatar') |
| 62 | ]; |
| 63 | |
| 64 | return $settings; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return bool|\WP_Error |
| 69 | */ |
| 70 | |
| 71 | public function validate_fields() |
| 72 | { |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Disable billing validation. |
| 78 | * |
| 79 | * @param $val |
| 80 | * |
| 81 | * @return bool |
| 82 | */ |
| 83 | public function should_validate_billing_details($val) |
| 84 | { |
| 85 | if ($this->is_billing_fields_removed()) $val = false; |
| 86 | |
| 87 | return $val; |
| 88 | } |
| 89 | |
| 90 | protected function billing_address_form() |
| 91 | { |
| 92 | if ($this->is_billing_fields_removed()) return; |
| 93 | |
| 94 | parent::billing_address_form(); |
| 95 | } |
| 96 | |
| 97 | public function process_payment($order_id, $subscription_id, $customer_id) |
| 98 | { |
| 99 | return (new CheckoutResponse())->set_is_success(true); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @param OrderEntity $order |
| 104 | * |
| 105 | * @return void |
| 106 | */ |
| 107 | public function frontend_bank_account_details($order) |
| 108 | { |
| 109 | static $cache = false; |
| 110 | |
| 111 | if (false === $cache && $order->payment_method == $this->id && ! $order->is_completed()) { |
| 112 | $cache = true; |
| 113 | $content = $this->get_value('account_details'); |
| 114 | echo '<div style="margin: 0 0 10px;">' . wpautop($content) . '</div>'; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | public function process_webhook() |
| 119 | { |
| 120 | |
| 121 | } |
| 122 | } |