Merge pull request #7694 from thenbrent/simplify_catch_exception
Catch exceptions in Simplify Commerce
This commit is contained in:
commit
9787478f83
|
@ -62,7 +62,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
|
|||
* @return bool
|
||||
*/
|
||||
protected function order_contains_subscription( $order_id ) {
|
||||
return class_exists( 'WC_Subscriptions_Order' ) && WC_Subscriptions_Order::order_contains_subscription( $order_id );
|
||||
return class_exists( 'WC_Subscriptions_Order' ) && ( WC_Subscriptions_Order::order_contains_subscription( $order_id ) || WC_Subscriptions_Renewal_Order::is_renewal( $order_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,6 +280,7 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
|
|||
return new WP_Error( 'simplify_error', __( 'Customer not found', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
try {
|
||||
// Charge the customer
|
||||
$payment = Simplify_Payment::createPayment( array(
|
||||
'amount' => $amount * 100, // In cents
|
||||
|
@ -295,6 +296,22 @@ class WC_Addons_Gateway_Simplify_Commerce extends WC_Gateway_Simplify_Commerce {
|
|||
'card.addressZip' => $order->billing_postcode
|
||||
) );
|
||||
|
||||
} catch ( Exception $e ) {
|
||||
|
||||
$error_message = $e->getMessage();
|
||||
|
||||
if ( $e instanceof Simplify_BadRequestException && $e->hasFieldErrors() && $e->getFieldErrors() ) {
|
||||
$error_message = '';
|
||||
foreach ( $e->getFieldErrors() as $error ) {
|
||||
$error_message .= ' ' . $error->getFieldName() . ': "' . $error->getMessage() . '" (' . $error->getErrorCode() . ')';
|
||||
}
|
||||
}
|
||||
|
||||
$order->add_order_note( sprintf( __( 'Simplify payment error: %s', 'woocommerce' ), $error_message ) );
|
||||
|
||||
return new WP_Error( 'simplify_payment_declined', $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
}
|
||||
|
||||
if ( 'APPROVED' == $payment->paymentStatus ) {
|
||||
// Payment complete
|
||||
$order->payment_complete( $payment->id );
|
||||
|
|
Loading…
Reference in New Issue