| @@ -225,13 +225,16 @@ | ||
| 225 | 225 | private function initPaymentGateways() { |
| 226 | 226 | if ( ! $this->gateway_manager ) { |
| 227 | 227 | $this->gateway_manager = new PaymentGatewayManager(); |
| 228 | 228 | |
| 229 | - // Register payment gateways. | |
| 230 | - $gateways = [ | |
| 231 | - new Gateways\PayPalGateway(), | |
| 232 | - new Gateways\ManualGateway(), | |
| 233 | - ]; | |
| 229 | + // Register payment gateways: PayPal, then one gateway per offline | |
| 230 | + // method (bank transfer, cheque, cash and any the merchant added). | |
| 231 | + // The single "Manual Payment" gateway of earlier versions is gone; | |
| 232 | + // setDefaultPaymentMethods() carries its enabled state over. | |
| 233 | + $gateways = [ new Gateways\PayPalGateway() ]; | |
| 234 | + foreach ( Services\OfflinePayments::methods() as $method ) { | |
| 235 | + $gateways[] = new Gateways\OfflineGateway( $method ); | |
| 236 | + } | |
| 234 | 237 | |
| 235 | 238 | foreach ( $gateways as $gateway ) { |
| 236 | 239 | $this->gateway_manager->registerGateway( $gateway ); |
| 237 | 240 | } |
| @@ -251,15 +254,27 @@ | ||
| 251 | 254 | * @access private |
| 252 | 255 | * @return void |
| 253 | 256 | */ |
| 254 | 257 | private function setDefaultPaymentMethods() { |
| 255 | - $payment_methods = get_option( 'easy_invoice_payment_methods', [] ); | |
| 258 | + $payment_methods = get_option( 'easy_invoice_payment_methods', null ); | |
| 259 | + if ( null === $payment_methods ) { | |
| 260 | + // First run: an invoice with no way to pay is a dead end, and bank | |
| 261 | + // transfer needs no account with anyone. The merchant can switch it | |
| 262 | + // off under Settings → Payment Methods. | |
| 263 | + update_option( 'easy_invoice_payment_methods', [ 'bank_transfer' ] ); | |
| 264 | + return; | |
| 265 | + } | |
| 266 | + $payment_methods = is_array( $payment_methods ) ? $payment_methods : []; | |
| 256 | 267 | |
| 257 | - $defaults_updated = false; | |
| 258 | - | |
| 259 | - // Bank Transfer, Cheque, and Cash payment defaults moved to Pro plugin | |
| 260 | - | |
| 261 | - if ( $defaults_updated ) { | |
| 268 | + // Sites that had "Manual Payment" switched on keep an offline option: | |
| 269 | + // its three sub-choices are gateways of their own now. | |
| 270 | + if ( in_array( 'manual', $payment_methods, true ) ) { | |
| 271 | + $payment_methods = array_values( array_diff( $payment_methods, [ 'manual' ] ) ); | |
| 272 | + foreach ( [ 'bank_transfer', 'cheque', 'cash' ] as $offline ) { | |
| 273 | + if ( ! in_array( $offline, $payment_methods, true ) ) { | |
| 274 | + $payment_methods[] = $offline; | |
| 275 | + } | |
| 276 | + } | |
| 262 | 277 | update_option( 'easy_invoice_payment_methods', array_unique( $payment_methods ) ); |
| 263 | 278 | } |
| 264 | 279 | } |
| 265 | 280 | |