Thanks for the link. Looks like this is never going to get implemented. What a shame. Can you at least tell me how to correctly hook into this function from functions.php?
You can see I’ve already edited the $metadata object directly in the plugin code by adding:
'order_tax' => $order->get_total_tax(),
But obviously it’s better to leave that alone and call it from the child theme.
public function generate_payment_request( $order, $prepared_payment_method ) {
$settings = get_option( 'woocommerce_stripe_settings', [] );
$statement_descriptor = ! empty( $settings['statement_descriptor'] ) ? str_replace( "'", '', $settings['statement_descriptor'] ) : '';
$short_statement_descriptor = ! empty( $settings['short_statement_descriptor'] ) ? str_replace( "'", '', $settings['short_statement_descriptor'] ) : '';
$is_short_statement_descriptor_enabled = ! empty( $settings['is_short_statement_descriptor_enabled'] ) && 'yes' === $settings['is_short_statement_descriptor_enabled'];
$capture = ! empty( $settings['capture'] ) && 'yes' === $settings['capture'] ? true : false;
$post_data = [];
$post_data['currency'] = strtolower( $order->get_currency() );
$post_data['amount'] = WC_Stripe_Helper::get_stripe_amount( $order->get_total(), $post_data['currency'] );
/* translators: 1) blog name 2) order number */
$post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );
$billing_email = $order->get_billing_email();
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
if ( ! empty( $billing_email ) && apply_filters( 'wc_stripe_send_stripe_receipt', false ) ) {
$post_data['receipt_email'] = $billing_email;
}
switch ( $order->get_payment_method() ) {
case 'stripe':
if ( $is_short_statement_descriptor_enabled && ! ( empty( $short_statement_descriptor ) && empty( $statement_descriptor ) ) ) {
$post_data['statement_descriptor'] = WC_Stripe_Helper::get_dynamic_statement_descriptor( $short_statement_descriptor, $order, $statement_descriptor );
} elseif ( ! empty( $statement_descriptor ) ) {
$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
}
$post_data['capture'] = $capture ? 'true' : 'false';
break;
case 'stripe_sepa':
if ( ! empty( $statement_descriptor ) ) {
$post_data['statement_descriptor'] = WC_Stripe_Helper::clean_statement_descriptor( $statement_descriptor );
}
// other payment methods error if we try to add a statement descriptor in the request
}
if ( method_exists( $order, 'get_shipping_postcode' ) && ! empty( $order->get_shipping_postcode() ) ) {
$post_data['shipping'] = [
'name' => trim( $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name() ),
'address' => [
'line1' => $order->get_shipping_address_1(),
'line2' => $order->get_shipping_address_2(),
'city' => $order->get_shipping_city(),
'country' => $order->get_shipping_country(),
'postal_code' => $order->get_shipping_postcode(),
'state' => $order->get_shipping_state(),
],
];
}
$post_data['expand[]'] = 'balance_transaction';
$metadata = [
__( 'customer_name', 'woocommerce-gateway-stripe' ) => sanitize_text_field( $billing_first_name ) . ' ' . sanitize_text_field( $billing_last_name ),
__( 'customer_email', 'woocommerce-gateway-stripe' ) => sanitize_email( $billing_email ),
'order_tax' => $order->get_total_tax(),
'order_id' => $order->get_order_number(),
'site_url' => esc_url( get_site_url() ),
];
if ( $this->has_subscription( $order->get_id() ) ) {
$metadata += [
'payment_type' => 'recurring',
];
}
$post_data['metadata'] = apply_filters( 'wc_stripe_payment_metadata', $metadata, $order, $prepared_payment_method );
if ( $prepared_payment_method->customer ) {
$post_data['customer'] = $prepared_payment_method->customer;
}
if ( ! empty( $prepared_payment_method->source ) ) {
$post_data['source'] = $prepared_payment_method->source;
}
if ( ! empty( $prepared_payment_method->payment_method ) ) {
$post_data['payment_method'] = $prepared_payment_method->payment_method;
}
/**
* Filter the return value of the WC_Payment_Gateway_CC::generate_payment_request.
*
* @since 3.1.0
* @param array $post_data
* @param WC_Order $order
* @param object $source
*/
return apply_filters( 'wc_stripe_generate_payment_request', $post_data, $order, $prepared_payment_method );
}