mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
Fix shipping preference for vaulted card button
This commit is contained in:
parent
fff2570124
commit
9ab091b945
3 changed files with 131 additions and 2 deletions
|
@ -24,12 +24,14 @@ class ShippingPreferenceFactory {
|
|||
* @param PurchaseUnit $purchase_unit Thw PurchaseUnit.
|
||||
* @param string $context The operation context like 'checkout', 'cart'.
|
||||
* @param WC_Cart|null $cart The current cart if relevant.
|
||||
* @param string $funding_source The funding source (PayPal button) like 'paypal', 'venmo', 'card'.
|
||||
* @return string
|
||||
*/
|
||||
public function from_state(
|
||||
PurchaseUnit $purchase_unit,
|
||||
string $context,
|
||||
?WC_Cart $cart = null
|
||||
?WC_Cart $cart = null,
|
||||
string $funding_source = ''
|
||||
): string {
|
||||
$contains_physical_goods = $purchase_unit->contains_physical_goods();
|
||||
if ( ! $contains_physical_goods ) {
|
||||
|
@ -49,6 +51,14 @@ class ShippingPreferenceFactory {
|
|||
return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
|
||||
}
|
||||
|
||||
if ( 'card' === $funding_source ) {
|
||||
if ( ! $has_shipping ) {
|
||||
return ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
|
||||
}
|
||||
// Looks like GET_FROM_FILE does not work for the vaulted card button.
|
||||
return ApplicationContext::SHIPPING_PREFERENCE_SET_PROVIDED_ADDRESS;
|
||||
}
|
||||
|
||||
return ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -334,7 +334,8 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
$shipping_preference = $this->shipping_preference_factory->from_state(
|
||||
$this->purchase_unit,
|
||||
$this->parsed_request_data['context'],
|
||||
WC()->cart
|
||||
WC()->cart,
|
||||
$this->parsed_request_data['funding_source'] ?? ''
|
||||
);
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue