Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send shipping or billing address to Stripe transaction
/**
* Send shipping or billing details to Stripe (required by some 3DSecure transactions/currencies)
*
* @param $post_data
* @param $order
*
* @return mixed
*/
function zpd_add_shipping_to_stripe( $post_data, $order ) {
/**
* If the shipping address exists, copy it to the Stripe transaction
*/
if ( ! empty( $order->get_shipping_postcode() ) ) {
$post_data['shipping'] = array(
'name' => $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name(),
'address' => array(
'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(),
)
);
}
/**
* If the billing address exists, copy it to the Stripe transaction.
* Note: this overwrites the shipping address.
* If you just need the shipping address detials in stripe, delete or comment-out the following code block.
*/
if ( ! empty( $order->get_billing_postcode() ) ) {
$post_data['shipping'] = array(
'name' => $order->get_billing_first_name() . ' ' . $order->get_billing_last_name(),
'address' => array(
'line1' => $order->get_billing_address_1(),
'line2' => $order->get_billing_address_2(),
'city' => $order->get_billing_city(),
'country' => $order->get_billing_country(),
'postal_code' => $order->get_billing_postcode(),
'state' => $order->get_billing_state(),
)
);
}
return $post_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment