@@ -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
0 commit comments