diff --git a/composer.json b/composer.json index b986e5c..0724fd5 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,7 @@ "php": ">=8.0", "ext-json": "*", "automattic/jetpack-autoloader": "^3.0", + "giggsey/libphonenumber-for-php": "^8.13", "justinrainbow/json-schema": "^5.2", "pronamic/wp-http": "^1.2", "pronamic/wp-mollie": "^1.6", diff --git a/src/AddressTransformer.php b/src/AddressTransformer.php index 625e29e..9ba29f8 100644 --- a/src/AddressTransformer.php +++ b/src/AddressTransformer.php @@ -10,6 +10,8 @@ namespace Pronamic\WordPress\Pay\Gateways\Mollie; +use libphonenumber\PhoneNumberFormat; +use libphonenumber\PhoneNumberUtil; use InvalidArgumentException; use Pronamic\WordPress\Mollie\Address as MollieAddress; use Pronamic\WordPress\Pay\Address as WordPressAddress; @@ -61,8 +63,12 @@ public function transform_wp_to_mollie( WordPressAddress $address ): MollieAddre $mollie_address = new MollieAddress( $given_name, $family_name, $email, $street_and_number, $city, $country ); + $phone_util = PhoneNumberUtil::getInstance(); + + $phone_number_object = $phone_util->parse( $address->get_phone(), $country ); + $mollie_address->organization_name = $address->get_company_name(); - $mollie_address->phone = $address->get_phone(); + $mollie_address->phone = $phone_util->format( $phone_number_object, PhoneNumberFormat::E164 ); $mollie_address->street_additional = $address->get_line_2(); $mollie_address->postal_code = $address->get_postal_code(); $mollie_address->region = $address->get_region();