paid-memberships-pro icon indicating copy to clipboard operation
paid-memberships-pro copied to clipboard

Breaking change not signaled in V2.8: Stipe Webhook - Address of automatic order was taken before from previous order, after is empty

Open Kilbourne opened this issue 1 year ago • 0 comments

Hi! In version 2.8 some parts of repeating logic of the Stripe webhook handler were extracted in pmpro_stripe_webhook_populate_order_from_payment function. But the workings are changed without any breaking change notice:

in 2.7 it was:

if ( ! empty ( $charge->billing_details->address->line1 ) ) {
...
} else {
	// Pull from previous order.
	$morder->find_billing_address();
}

in 2.8 it's :

$order->billing = new stdClass();
$order->billing->name = empty($payment_method->billing_details->name) ? '' : $payment_method->billing_details->name;
$order->billing->street = empty($payment_method->billing_details->address->line1) ? '' : $payment_method->billing_details->address->line1;
$order->billing->city = empty($payment_method->billing_details->address->city) ? '' : $payment_method->billing_details->address->city;
$order->billing->state = empty($payment_method->billing_details->address->state) ? '' : $payment_method->billing_details->address->state;
$order->billing->zip = empty($payment_method->billing_details->address->postal_code) ? '' : $payment_method->billing_details->address->postal_code;
$order->billing->country = empty($payment_method->billing_details->address->country) ? '' : $payment_method->billing_details->address->country;
$order->billing->phone = empty($payment_method->billing_details->phone) ? '' : $payment_method->billing_details->phone;

So while in 2.7 was taken from old order when address is not present, in 2.8 it is empty

Not sure if it's by design or a bug, but in any case it should have been present in the changelog ( I notice just now as we are going to pay VAT and the amount is based on the country of orders)

The patch i'm currently applying:

if ( ! empty ( $payment_method->billing_details->address->line1 ) ) {
		$order->billing = new stdClass();
		$order->billing->name = empty($payment_method->billing_details->name) ? '' : $payment_method->billing_details->name;
		$order->billing->street = empty($payment_method->billing_details->address->line1) ? '' : $payment_method->billing_details->address->line1;
		$order->billing->city = empty($payment_method->billing_details->address->city) ? '' : $payment_method->billing_details->address->city;
		$order->billing->state = empty($payment_method->billing_details->address->state) ? '' : $payment_method->billing_details->address->state;
		$order->billing->zip = empty($payment_method->billing_details->address->postal_code) ? '' : $payment_method->billing_details->address->postal_code;
		$order->billing->country = empty($payment_method->billing_details->address->country) ? '' : $payment_method->billing_details->address->country;
		$order->billing->phone = empty($payment_method->billing_details->phone) ? '' : $payment_method->billing_details->phone;

		$name_parts = empty($payment_method->billing_details->name) ? [] : pnp_split_full_name($payment_method->billing_details->name);
		$order->FirstName = empty($name_parts['fname']) ? '' : $name_parts['fname'];
		$order->LastName = empty($name_parts['lname']) ? '' : $name_parts['lname'];
		$order->Email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID = '" . esc_sql($order->user_id) . "' LIMIT 1");
		$order->Address1 = $order->billing->street;
		$order->City = $order->billing->city;
		$order->State = $order->billing->state;
		$order->Zip = $order->billing->zip;
		$order->Country = $order->billing->country;
		$order->PhoneNumber = $order->billing->phone;
}else{
		$order->find_billing_address();
}

Kilbourne avatar Oct 11 '22 09:10 Kilbourne