Skip to content

Commit cc205e5

Browse files
committed
Merge pull request #107 from skyverge/4.1.2
2 parents 135cc41 + 718aa81 commit cc205e5

File tree

6 files changed

+112
-49
lines changed

6 files changed

+112
-49
lines changed

woocommerce/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
*** SkyVerge WooCommerce Plugin Framework Changelog ***
22

3+
2015.11.05 - version 4.1.2
4+
* Tweak - Misc Payment Gateway framework improvements
5+
36
2015.09.09 - version 4.1.1
47
* Fix - For Subscriptions 1.5, don't mark the original order as failed when a renewal payment fails
58

woocommerce/class-sv-wc-plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
* Use the standard WordPress/WooCommerce `is_*` methods when adding the notice
8585
* to control which pages it does (or does not) display on.
8686
*
87-
* @version 4.1.1
87+
* @version 4.1.2
8888
*/
8989
abstract class SV_WC_Plugin {
9090

9191
/** Plugin Framework Version */
92-
const VERSION = '4.1.1';
92+
const VERSION = '4.1.2';
9393

9494
/** @var object single instance of plugin */
9595
protected static $instance;

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

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -561,19 +561,34 @@ public function get_order( $order_id ) {
561561
* instance for use in credit card capture transactions. Standard information
562562
* can include:
563563
*
564-
* $order->capture_total - the capture total
564+
* $order->capture->amount - amount to capture (partial captures are not supported by the framework yet)
565+
* $order->capture->description - capture description
566+
* $order->capture->trans_id - transaction ID for the order being captured
567+
*
568+
* included for backwards compat (4.1 and earlier)
569+
*
570+
* $order->capture_total
571+
* $order->description
565572
*
566573
* @since 2.0.0
567574
* @param WC_Order $order order being processed
568575
* @return WC_Order object with payment and transaction information attached
569576
*/
570577
protected function get_order_for_capture( $order ) {
571578

572-
// set capture total here so it can be modified later as needed prior to capture
573-
$order->capture_total = number_format( $order->get_total(), 2, '.', '' );
579+
if ( is_numeric( $order ) ) {
580+
$order = wc_get_order( $order );
581+
}
574582

575-
// capture-specific order description
576-
$order->description = sprintf( _x( '%s - Capture for Order %s', 'Capture order description', $this->text_domain ), esc_html( get_bloginfo( 'name' ) ), $order->get_order_number() );
583+
// add capture info
584+
$order->capture = new stdClass();
585+
$order->capture->amount = SV_WC_Helper::number_format( $order->get_total() );
586+
$order->capture->description = sprintf( __( '%s - Capture for Order %s', $this->get_text_domain() ), wp_specialchars_decode( get_bloginfo( 'name' ) ), $order->get_order_number() );
587+
$order->capture->trans_id = $this->get_order_meta( $order->id, 'trans_id' );
588+
589+
// backwards compat for 4.1 and earlier
590+
$order->capture_total = $order->capture->amount;
591+
$order->description = $order->capture->description;
577592

578593
return apply_filters( 'wc_payment_gateway_' . $this->get_id() . '_get_order_for_capture', $order, $this );
579594
}
@@ -1146,24 +1161,7 @@ public function create_payment_token( $order, $response = null, $environment_id
11461161
$this->add_payment_token( $order->get_user_id(), $token, $environment_id );
11471162
}
11481163

1149-
// order note based on gateway type
1150-
if ( $this->is_credit_card_gateway() ) {
1151-
$message = sprintf( _x( '%s Payment Method Saved: %s ending in %s (expires %s)', 'Supports direct credit card tokenization', $this->text_domain ),
1152-
$this->get_method_title(),
1153-
$token->get_type_full(),
1154-
$token->get_last_four(),
1155-
$token->get_exp_date()
1156-
);
1157-
} elseif ( $this->is_echeck_gateway() ) {
1158-
// account type (checking/savings) may or may not be available, which is fine
1159-
$message = sprintf( _x( '%s eCheck Payment Method Saved: %s account ending in %s', 'Supports direct cheque tokenization', $this->text_domain ),
1160-
$this->get_method_title(),
1161-
$token->get_account_type(),
1162-
$token->get_last_four()
1163-
);
1164-
}
1165-
1166-
$order->add_order_note( $message );
1164+
$order->add_order_note( $this->get_saved_payment_token_order_note( $token ) );
11671165

11681166
// add the standard transaction data
11691167
$this->add_transaction_data( $order, $response );
@@ -1197,6 +1195,38 @@ public function create_payment_token( $order, $response = null, $environment_id
11971195
}
11981196

11991197

1198+
/**
1199+
* Get the order note message when a customer saves their payment method
1200+
* to their account
1201+
*
1202+
* @since 4.1.2
1203+
* @param \SV_WC_Payment_Gateway_Payment_Token $token the payment token being saved
1204+
* @return string
1205+
*/
1206+
protected function get_saved_payment_token_order_note( $token ) {
1207+
1208+
$message = '';
1209+
1210+
if ( $this->is_credit_card_gateway() ) {
1211+
$message = sprintf( _x( '%s Payment Method Saved: %s ending in %s (expires %s)', 'Supports direct credit card tokenization', $this->text_domain ),
1212+
$this->get_method_title(),
1213+
$token->get_type_full(),
1214+
$token->get_last_four(),
1215+
$token->get_exp_date()
1216+
);
1217+
} elseif ( $this->is_echeck_gateway() ) {
1218+
// account type (checking/savings) may or may not be available, which is fine
1219+
$message = sprintf( _x( '%s eCheck Payment Method Saved: %s account ending in %s', 'Supports direct cheque tokenization', $this->text_domain ),
1220+
$this->get_method_title(),
1221+
$token->get_account_type(),
1222+
$token->get_last_four()
1223+
);
1224+
}
1225+
1226+
return $message;
1227+
}
1228+
1229+
12001230
/**
12011231
* Returns true if tokenization should be forced on the checkout page,
12021232
* false otherwise. This is most useful to force tokenization for a
@@ -1876,7 +1906,7 @@ protected function do_add_payment_method_transaction( WC_Order $order ) {
18761906
} else {
18771907

18781908
if ( $response->get_status_code() && $response->get_status_message() ) {
1879-
$message = sprintf( 'Status codes %s: %s', $response->get_status_code(), $response->get_status_message() );
1909+
$message = sprintf( 'Status code %s: %s', $response->get_status_code(), $response->get_status_message() );
18801910
} elseif ( $response->get_status_code() ) {
18811911
$message = sprintf( 'Status code: %s', $response->get_status_code() );
18821912
} elseif ( $response->get_status_message() ) {
@@ -1921,6 +1951,9 @@ protected function get_order_for_add_payment_method() {
19211951

19221952
$order = new WC_Order( 0 );
19231953

1954+
// default to base store currency
1955+
$order->order_currency = get_woocommerce_currency();
1956+
19241957
// mock order, as all gateway API implementations require an order object for tokenization
19251958
$order = $this->get_order( $order );
19261959

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected function get_payment_method_actions( $token ) {
385385
// make default
386386
if ( ! $token->is_default() ) {
387387

388-
$actions[] = array(
388+
$actions['make_default'] = array(
389389
'url' => wp_nonce_url( add_query_arg( array(
390390
'wc-' . $this->get_plugin()->get_id_dasherized() . '-token' => $token->get_token(),
391391
'wc-' . $this->get_plugin()->get_id_dasherized() . '-action' => 'make-default'
@@ -396,7 +396,7 @@ protected function get_payment_method_actions( $token ) {
396396
}
397397

398398
// delete
399-
$actions[] = array(
399+
$actions['delete'] = array(
400400
'url' => wp_nonce_url( add_query_arg( array(
401401
'wc-' . $this->get_plugin()->get_id_dasherized() . '-token' => $token->get_token(),
402402
'wc-' . $this->get_plugin()->get_id_dasherized() . '-action' => 'delete'
@@ -405,7 +405,6 @@ protected function get_payment_method_actions( $token ) {
405405
'name' => __( 'Delete', $this->get_plugin()->get_text_domain() ),
406406
);
407407

408-
409408
return apply_filters( 'wc_' . $this->get_plugin()->get_id() . '_my_payment_methods_table_method_actions', $actions, $token, $this );
410409
}
411410

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,24 @@ public function render_fieldset_start() {
823823
public function render_payment_fields() {
824824

825825
foreach ( $this->get_payment_fields() as $field ) {
826-
woocommerce_form_field( $field['name'], $field, $field['value'] );
826+
$this->render_payment_field( $field );
827827
}
828828
}
829829

830830

831+
/**
832+
* Render the payment, a simple wrapper around woocommerce_form_field() to
833+
* make it more convenient for concrete gateways to override form output
834+
*
835+
* @since 4.1.2
836+
* @param array $field
837+
*/
838+
protected function render_payment_field( $field ) {
839+
840+
woocommerce_form_field( $field['name'], $field, $field['value'] );
841+
}
842+
843+
831844
/**
832845
* Render the payment form closing fieldset tag, clearing div, and "save
833846
* payment method" checkbox

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

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ public function payment_fields() {
609609

610610
if ( $this->supports_payment_form() ) {
611611

612-
$form = new SV_WC_Payment_Gateway_Payment_Form( $this );
613-
614-
$form->render();
612+
$this->get_payment_form_instance()->render();
615613

616614
} else {
617615

@@ -620,6 +618,18 @@ public function payment_fields() {
620618
}
621619

622620

621+
/**
622+
* Get the payment form class instance
623+
*
624+
* @since 4.1.2
625+
* @return \SV_WC_Payment_Gateway_Payment_Form
626+
*/
627+
public function get_payment_form_instance() {
628+
629+
return new SV_WC_Payment_Gateway_Payment_Form( $this );
630+
}
631+
632+
623633
/**
624634
* Get the payment form field defaults, primarily for gateways to override
625635
* and set dummy credit card/eCheck info when in the test environment
@@ -737,20 +747,6 @@ public function init_form_fields() {
737747
$this->form_fields = $this->add_tokenization_form_fields( $this->form_fields );
738748
}
739749

740-
// if there is more than just the production environment available
741-
if ( count( $this->get_environments() ) > 1 ) {
742-
$this->form_fields = $this->add_environment_form_fields( $this->form_fields );
743-
}
744-
745-
// add the "inherit settings" toggle if there are settings shared with a sibling gateway
746-
if ( count( $this->shared_settings ) ) {
747-
$this->form_fields = $this->add_shared_settings_form_fields( $this->form_fields );
748-
}
749-
750-
// add unique method fields added by concrete gateway class
751-
$gateway_form_fields = $this->get_method_form_fields();
752-
$this->form_fields = array_merge( $this->form_fields, $gateway_form_fields );
753-
754750
// add "detailed customer decline messages" option if the feature is supported
755751
if ( $this->supports( self::FEATURE_DETAILED_CUSTOMER_DECLINE_MESSAGES ) ) {
756752
$this->form_fields['enable_customer_decline_messages'] = array(
@@ -761,7 +757,7 @@ public function init_form_fields() {
761757
);
762758
}
763759

764-
// add any common bottom fields
760+
// debug mode
765761
$this->form_fields['debug_mode'] = array(
766762
'title' => __( 'Debug Mode', $this->text_domain ),
767763
'type' => 'select',
@@ -775,6 +771,20 @@ public function init_form_fields() {
775771
),
776772
);
777773

774+
// if there is more than just the production environment available
775+
if ( count( $this->get_environments() ) > 1 ) {
776+
$this->form_fields = $this->add_environment_form_fields( $this->form_fields );
777+
}
778+
779+
// add the "inherit settings" toggle if there are settings shared with a sibling gateway
780+
if ( count( $this->shared_settings ) ) {
781+
$this->form_fields = $this->add_shared_settings_form_fields( $this->form_fields );
782+
}
783+
784+
// add unique method fields added by concrete gateway class
785+
$gateway_form_fields = $this->get_method_form_fields();
786+
$this->form_fields = array_merge( $this->form_fields, $gateway_form_fields );
787+
778788
// add the special 'shared-settings-field' class name to any shared settings fields
779789
foreach ( $this->shared_settings as $field_name ) {
780790
$this->form_fields[ $field_name ]['class'] = trim( isset( $this->form_fields[ $field_name ]['class'] ) ? $this->form_fields[ $field_name ]['class'] : '' ) . ' shared-settings-field';
@@ -866,6 +876,11 @@ protected function add_shared_settings_form_fields( $form_fields ) {
866876
}
867877
}
868878

879+
$form_fields['connection_settings'] = array(
880+
'title' => esc_html__( 'Connection Settings', $this->text_domain ),
881+
'type' => 'title',
882+
);
883+
869884
// disable the field if the sibling gateway is already inheriting settings
870885
$form_fields['inherit_settings'] = array(
871886
'title' => _x( 'Share connection settings', 'Supports sibling gateways', $this->text_domain ),
@@ -1101,7 +1116,7 @@ public function get_payment_method_image_url( $type ) {
11011116
break;
11021117

11031118
case 'paypal':
1104-
$image_type = 'paypal-1';
1119+
$image_type = 'paypal';
11051120
break;
11061121

11071122
case 'visa debit':

0 commit comments

Comments
 (0)