mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add option for sending billing data
This commit is contained in:
parent
fb0bd85da6
commit
8c77258828
5 changed files with 30 additions and 4 deletions
|
@ -13,7 +13,7 @@ class CheckoutActionHandler {
|
||||||
configuration() {
|
configuration() {
|
||||||
const spinner = this.spinner;
|
const spinner = this.spinner;
|
||||||
const createOrder = (data, actions) => {
|
const createOrder = (data, actions) => {
|
||||||
const payer = payerData();
|
let payer = payerData();
|
||||||
const bnCode = typeof this.config.bn_codes[this.config.context] !== 'undefined' ?
|
const bnCode = typeof this.config.bn_codes[this.config.context] !== 'undefined' ?
|
||||||
this.config.bn_codes[this.config.context] : '';
|
this.config.bn_codes[this.config.context] : '';
|
||||||
|
|
||||||
|
@ -26,6 +26,13 @@ class CheckoutActionHandler {
|
||||||
|
|
||||||
const createaccount = jQuery('#createaccount').is(":checked") ? true : false;
|
const createaccount = jQuery('#createaccount').is(":checked") ? true : false;
|
||||||
|
|
||||||
|
const paymentMethod = getCurrentPaymentMethod();
|
||||||
|
const fundingSource = window.ppcpFundingSource;
|
||||||
|
|
||||||
|
if (fundingSource === 'card' && !PayPalCommerceGateway.use_form_billing_data_for_cards) {
|
||||||
|
payer = null;
|
||||||
|
}
|
||||||
|
|
||||||
return fetch(this.config.ajax.create_order.endpoint, {
|
return fetch(this.config.ajax.create_order.endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -34,8 +41,8 @@ class CheckoutActionHandler {
|
||||||
bn_code:bnCode,
|
bn_code:bnCode,
|
||||||
context:this.config.context,
|
context:this.config.context,
|
||||||
order_id:this.config.order_id,
|
order_id:this.config.order_id,
|
||||||
payment_method: getCurrentPaymentMethod(),
|
payment_method: paymentMethod,
|
||||||
funding_source: window.ppcpFundingSource,
|
funding_source: fundingSource,
|
||||||
form: formJsonObj,
|
form: formJsonObj,
|
||||||
createaccount: createaccount
|
createaccount: createaccount
|
||||||
})
|
})
|
||||||
|
|
|
@ -867,6 +867,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),
|
'single_product_buttons_enabled' => $this->settings->has( 'button_product_enabled' ) && $this->settings->get( 'button_product_enabled' ),
|
||||||
'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ),
|
'mini_cart_buttons_enabled' => $this->settings->has( 'button_mini-cart_enabled' ) && $this->settings->get( 'button_mini-cart_enabled' ),
|
||||||
'basic_checkout_validation_enabled' => $this->basic_checkout_validation_enabled,
|
'basic_checkout_validation_enabled' => $this->basic_checkout_validation_enabled,
|
||||||
|
'use_form_billing_data_for_cards' => $this->settings->has( 'use_form_billing_data_for_cards' ) && $this->settings->get( 'use_form_billing_data_for_cards' ),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
|
if ( $this->style_for_context( 'layout', 'mini-cart' ) !== 'horizontal' ) {
|
||||||
|
|
|
@ -404,7 +404,10 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $payer && isset( $data['form'] ) ) {
|
$use_form_billing_data_for_cards = $this->settings->has( 'use_form_billing_data_for_cards' ) &&
|
||||||
|
(bool) $this->settings->get( 'use_form_billing_data_for_cards' );
|
||||||
|
|
||||||
|
if ( ! $payer && isset( $data['form'] ) && $use_form_billing_data_for_cards ) {
|
||||||
$form_fields = $data['form'];
|
$form_fields = $data['form'];
|
||||||
|
|
||||||
if ( is_array( $form_fields ) && isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
if ( is_array( $form_fields ) && isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
||||||
|
|
|
@ -854,6 +854,20 @@ return array(
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
'gateway' => 'paypal',
|
'gateway' => 'paypal',
|
||||||
),
|
),
|
||||||
|
'use_form_billing_data_for_cards' => array(
|
||||||
|
'title' => __( 'Send billing data for cards', 'woocommerce-paypal-payments' ),
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'desc_tip' => true,
|
||||||
|
'label' => __( 'Send Checkout billing form data to PayPal smart card fields', 'woocommerce-paypal-payments' ),
|
||||||
|
'description' => __( 'This increases convenience for the users, but can cause issues if card details do not match the billing data.', 'woocommerce-paypal-payments' ),
|
||||||
|
'default' => false,
|
||||||
|
'screens' => array(
|
||||||
|
State::STATE_START,
|
||||||
|
State::STATE_ONBOARDED,
|
||||||
|
),
|
||||||
|
'requirements' => array(),
|
||||||
|
'gateway' => 'paypal',
|
||||||
|
),
|
||||||
|
|
||||||
// General button styles.
|
// General button styles.
|
||||||
'button_style_heading' => array(
|
'button_style_heading' => array(
|
||||||
|
|
|
@ -152,6 +152,7 @@ class CreateOrderEndpointTest extends TestCase
|
||||||
$session_handler = Mockery::mock(SessionHandler::class);
|
$session_handler = Mockery::mock(SessionHandler::class);
|
||||||
$settings = Mockery::mock(Settings::class);
|
$settings = Mockery::mock(Settings::class);
|
||||||
$early_order_handler = Mockery::mock(EarlyOrderHandler::class);
|
$early_order_handler = Mockery::mock(EarlyOrderHandler::class);
|
||||||
|
$settings->shouldReceive('has')->andReturnFalse();
|
||||||
|
|
||||||
$testee = new CreateOrderEndpoint(
|
$testee = new CreateOrderEndpoint(
|
||||||
$request_data,
|
$request_data,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue