Skip to content

Commit c4d82fe

Browse files
committed
Handle payment result select values
1 parent d5472a3 commit c4d82fe

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

includes/Bogus_Gateway.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,32 @@ public function process_payment( $order_id ) {
183183

184184
$order = wc_get_order( $order_id );
185185

186-
// Update order status and add a transaction note
187-
$order->payment_complete();
188-
$order->add_order_note( __( 'Bogus is always approved 😎', 'woocommerce-dev-helper' ) );
186+
$result = ! empty( $_POST[ "{$this->id}_payment_result" ] ) ? $_POST[ "{$this->id}_payment_result" ] : self::PAYMENT_RESULT_APPROVED;
187+
188+
// halt on decline
189+
if ( self::PAYMENT_RESULT_DECLINED === $result ) {
190+
191+
$message = __( 'Sorry, the payment was bogus 😳', 'woocommerce-dev-helper' );
192+
193+
if ( ! $order->has_status( 'failed' ) ) {
194+
$order->update_status( 'failed', $message );
195+
} else {
196+
$order->add_order_note( $message );
197+
}
198+
199+
throw new \Exception( $message );
200+
}
201+
202+
// update the order status accordingly
203+
if ( self::PAYMENT_RESULT_HELD === $result ) {
204+
205+
$order->update_status( 'on-hold', __( 'The payment may be bogus, holding the order 🤔', 'woocommerce-dev-helper' ) );
206+
207+
} else {
208+
209+
$order->payment_complete();
210+
$order->add_order_note( __( 'Payment approved 😎', 'woocommerce-dev-helper' ) );
211+
}
189212

190213
// Remove cart
191214
WC()->cart->empty_cart();

0 commit comments

Comments
 (0)