Get payer info from checkout form (WIP)

This commit is contained in:
dinamiko 2022-02-04 17:11:40 +01:00
parent 2f87393d4d
commit 7b132f9d92
2 changed files with 28 additions and 0 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\ApiClient\Factory;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Address;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerTaxInfo;
@ -147,4 +148,23 @@ class PayerFactory {
$tax_info
);
}
public function from_checkout_form(array $data) {
$first_name = $data['billing_first_name'] ?? '';
$last_name = $data['billing_last_name'] ?? '';
$billing_email = $data['billing_email'] ?? '';
$billing_country = $data['billing_country'] ?? '';
$billing_address_1 = $data['billing_address_1'] ?? '';
return new Payer(
new PayerName($first_name, $last_name),
$billing_email,
'',
new Address(
$billing_country,
$billing_address_1
)
);
}
}

View file

@ -12,8 +12,10 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Address;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentMethod;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
@ -337,6 +339,12 @@ class CreateOrderEndpoint implements EndpointInterface {
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
}
if(!$payer && isset($data['form'])) {
parse_str($data['form'], $output);
return $this->payer_factory->from_checkout_form($output);
}
return $payer;
}