enable gateways in the account -> order -> pay-now

This commit is contained in:
David Remer 2020-09-30 14:24:31 +03:00
parent 324ff49496
commit 96fd3d6a2a
10 changed files with 302 additions and 58 deletions

View file

@ -43,7 +43,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Repository\PartnerReferralsData;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayeeRepository;
use WooCommerce\PayPalCommerce\ApiClient\Repository\PayPalRequestIdRepository;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
use WpOop\TransientCache\CachePoolFactory;
return array(
'api.host' => function( $container ) : string {

View file

@ -36,6 +36,42 @@ class PayerFactory {
$this->address_factory = $address_factory;
}
/**
* Returns a Payer entity from a WooCommerce order.
*
* @param \WC_Order $wc_order The WooCommerce order.
*
* @return Payer
*/
public function from_wc_order( \WC_Order $wc_order ): Payer {
$payer_id = '';
$birthdate = null;
$phone = null;
if ( $wc_order->get_billing_phone() ) {
// make sure the phone number contains only numbers and is max 14. chars long.
$national_number = $wc_order->get_billing_phone();
$national_number = preg_replace( '/[^0-9]/', '', $national_number );
$national_number = substr( $national_number, 0, 14 );
$phone = new PhoneWithType(
'HOME',
new Phone( $national_number )
);
}
return new Payer(
new PayerName(
$wc_order->get_billing_first_name(),
$wc_order->get_billing_last_name()
),
$wc_order->get_billing_email(),
$payer_id,
$this->address_factory->from_wc_order( $wc_order, 'billing' ),
$birthdate,
$phone
);
}
/**
* Returns a Payer object based off a WooCommerce customer.
*