Skip to content

Commit 6a6f2bf

Browse files
committed
Payment Gateway Framework Fixes, Refactors, Tweaks
Couple of small fixes, tweaks, refactors, and documentation updates for the payment gateway framework
1 parent 23d0acf commit 6a6f2bf

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

woocommerce/class-sv-wc-plugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,10 @@ public function get_api_log_message( $data ) {
452452

453453
$messages = array();
454454

455-
$messages[] = isset( $data['uri'] ) ? 'Request' : 'Response';
455+
$messages[] = isset( $data['uri'] ) && $data['uri'] ? 'Request' : 'Response';
456456

457457
foreach ( (array) $data as $key => $value ) {
458-
459-
$messages[] = sprintf( '%s: %s', $key, is_array( $value ) ? print_r( $value, true ) : $value );
458+
$messages[] = sprintf( '%s: %s', $key, is_array( $value ) || ( is_object( $value ) && 'stdClass' == get_class( $value ) ) ? print_r( (array) $value, true ) : $value );
460459
}
461460

462461
return implode( "\n", $messages );

woocommerce/payment-gateway/class-sv-wc-payment-gateway-direct.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,15 +1191,19 @@ public function remove_subscription_renewal_order_meta( $order_meta_query, $orig
11911191
$order_meta_query .= $this->get_remove_subscription_renewal_order_meta(
11921192
array(
11931193
'_wc_' . $this->get_id() . '_trans_id',
1194+
'_wc_' . $this->get_id() . '_trans_date',
11941195
'_wc_' . $this->get_id() . '_payment_token',
11951196
'_wc_' . $this->get_id() . '_account_four',
11961197
'_wc_' . $this->get_id() . '_card_expiry_date',
11971198
'_wc_' . $this->get_id() . '_card_type',
11981199
'_wc_' . $this->get_id() . '_authorization_code',
1200+
'_wc_' . $this->get_id() . '_auth_can_be_captured',
1201+
'_wc_' . $this->get_id() . '_charge_captured',
11991202
'_wc_' . $this->get_id() . '_account_type',
12001203
'_wc_' . $this->get_id() . '_check_number',
12011204
'_wc_' . $this->get_id() . '_environment',
12021205
'_wc_' . $this->get_id() . '_customer_id',
1206+
'_wc_' . $this->get_id() . '_retry_count',
12031207
)
12041208
);
12051209
}

woocommerce/payment-gateway/class-sv-wc-payment-gateway-hosted.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ public function process_redirect_back() {
420420
return wp_redirect( $this->get_return_url( $order ) );
421421
} else {
422422
// failed response, redirect back to pay page
423-
return wp_redirect( $order->get_checkout_payment_url( $this->use_form_post() ) );
423+
return wp_redirect( $order->get_checkout_payment_url( $this->use_form_post() && ! $this->use_auto_form_post() ) );
424424
}
425425

426426
} catch( Exception $e ) {
427427
// failure
428428

429429
if ( isset( $order ) && $order ) {
430430
$this->mark_order_as_failed( $order, $e->getMessage(), $response );
431-
return wp_redirect( $order->get_checkout_payment_url( $this->use_form_post() ) );
431+
return wp_redirect( $order->get_checkout_payment_url( $this->use_form_post() && ! $this->use_auto_form_post() ) );
432432
}
433433

434434
// otherwise, if no order is available, log the issue and redirect to home
@@ -550,7 +550,7 @@ protected function add_transaction_data( $order, $response = null ) {
550550
*
551551
* @since 2.1-1
552552
* @param WC_Order $order the order
553-
* @param SV_WC_Payment_Gateway_API_Payment_Notification_Response transaction response
553+
* @param SV_WC_Payment_Gateway_API_Payment_Notification_Credit_Card_Response transaction response
554554
*/
555555
protected function do_credit_card_transaction_approved( $order, $response ) {
556556

woocommerce/payment-gateway/class-sv-wc-payment-gateway.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,16 @@
113113
*
114114
* ### Logging
115115
*
116-
* You are responsible for handling your own logging, though some helper
117-
* methods and best practices are defined.
116+
* You are responsible for firing an action from your API/response class to provide
117+
* logging of the request/response.
118118
*
119-
* A recommended implementation strategy for direct payment gateways is to
120-
* do an action from within the API class, immediately after the remote request,
121-
* for instance like:
119+
* From within the API class, immediately after the remote request, for instance like:
122120
*
123121
* do_action( 'wc_intuit_qbms_api_request_performed', $request_data, $response_data );
124122
*
125-
* Hook into this action from your child class constructor, ie:
126-
*
127-
* add_action( 'wc_intuit_qbms_api_request_performed', array( $this, 'log_api_communication' ), 10, 2 );
128-
*
129-
* Then define your own log_api_communication method, making use of
130-
* add_debug_message() method if so desired, ie:
131-
*
132-
* $this->add_debug_message( sprintf( __( "Request Method: %s\nRequest URI: %s\nRequest Body: %s", My_Gateway::TEXT_DOMAIN ), $request['method'], $request['uri'], $request['body'] ), 'message', true );
123+
* Where $request_data and $response_data are associative arrays. Don't
124+
* forget to fire the action even when errors occur and when handling exceptions
125+
* even if there isn't any response data to pass (that parameter is optional)
133126
*
134127
* This will have the effect of logging every communication request with the
135128
* remote endpoint, without you having to litter your code with logging calls,
@@ -1029,6 +1022,21 @@ protected function get_order( $order ) {
10291022

10301023
$order->description = sprintf( _x( '%s - Order %s', 'Order description', $this->text_domain ), esc_html( get_bloginfo( 'name' ) ), $order->get_order_number() );
10311024

1025+
$order = $this->get_order_with_unique_transaction_ref( $order );
1026+
1027+
return $order;
1028+
}
1029+
1030+
1031+
/**
1032+
* Returns the $order object with a unique transaction ref member added
1033+
*
1034+
* @since 2.1-1
1035+
* @param WC_Order $order the order object
1036+
* @return WC_Order order object with member named unique_transaction_ref
1037+
*/
1038+
protected function get_order_with_unique_transaction_ref( $order ) {
1039+
10321040
// generate a unique retry count
10331041
if ( is_numeric( SV_WC_Plugin_Compatibility::get_order_custom_field( $order, 'wc_' . $this->get_id() . '_retry_count' ) ) ) {
10341042
$retry_count = SV_WC_Plugin_Compatibility::get_order_custom_field( $order, 'wc_' . $this->get_id() . '_retry_count' );
@@ -1712,7 +1720,7 @@ protected function add_debug_message( $message, $type = 'message', $set_message
17121720
}
17131721

17141722
// add debug message to woocommerce->errors/messages if checkout or both is enabled
1715-
if ( ( $this->debug_checkout() || $this->is_test_environment() ) && ! is_admin() ) {
1723+
if ( ( $this->debug_checkout() || ( 'error' === $type && $this->is_test_environment() ) ) && ( ! is_admin() || defined( 'DOING_AJAX' ) ) ) {
17161724

17171725
if ( 'message' === $type ) {
17181726

0 commit comments

Comments
 (0)