Skip to content

Commit

Permalink
Format phone number in E164 format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Oct 18, 2024
1 parent 5249c39 commit 170252d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/AddressTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Check failure on line 68 in src/AddressTransformer.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Parameter #1 $numberToParse of method libphonenumber\PhoneNumberUtil::parse() expects string, string|null given.

$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();
Expand Down

0 comments on commit 170252d

Please sign in to comment.