mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Allow skip ditch items when mismatch
This commit is contained in:
parent
526c25f501
commit
15a6685ff2
2 changed files with 62 additions and 58 deletions
|
@ -111,7 +111,7 @@ class PayUponInvoiceOrderEndpoint {
|
||||||
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL',
|
||||||
'purchase_units' => array_map(
|
'purchase_units' => array_map(
|
||||||
static function ( PurchaseUnit $item ): array {
|
static function ( PurchaseUnit $item ): array {
|
||||||
return $item->to_array();
|
return $item->to_array( false );
|
||||||
},
|
},
|
||||||
$items
|
$items
|
||||||
),
|
),
|
||||||
|
@ -230,8 +230,7 @@ class PayUponInvoiceOrderEndpoint {
|
||||||
* @param array $items
|
* @param array $items
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function ensure_taxes(WC_Order $wc_order, array $data): array
|
private function ensure_taxes( WC_Order $wc_order, array $data ): array {
|
||||||
{
|
|
||||||
$items = array_map(
|
$items = array_map(
|
||||||
function ( WC_Order_Item_Product $item ) use ( $wc_order ): Item {
|
function ( WC_Order_Item_Product $item ) use ( $wc_order ): Item {
|
||||||
$product = $item->get_product();
|
$product = $item->get_product();
|
||||||
|
@ -247,8 +246,11 @@ class PayUponInvoiceOrderEndpoint {
|
||||||
mb_substr( $item->get_name(), 0, 127 ),
|
mb_substr( $item->get_name(), 0, 127 ),
|
||||||
new Money( $wc_order->get_item_subtotal( $item, false, false ), $currency ),
|
new Money( $wc_order->get_item_subtotal( $item, false, false ), $currency ),
|
||||||
$quantity,
|
$quantity,
|
||||||
substr(wp_strip_all_tags($product instanceof WC_Product ? $product->get_description() : ''),
|
substr(
|
||||||
0, 127) ?: '',
|
wp_strip_all_tags( $product instanceof WC_Product ? $product->get_description() : '' ),
|
||||||
|
0,
|
||||||
|
127
|
||||||
|
) ?: '',
|
||||||
$tax,
|
$tax,
|
||||||
$product instanceof WC_Product ? $product->get_sku() : '',
|
$product instanceof WC_Product ? $product->get_sku() : '',
|
||||||
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
( $product instanceof WC_Product && $product->is_virtual() ) ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS,
|
||||||
|
|
|
@ -268,9 +268,11 @@ class PurchaseUnit {
|
||||||
/**
|
/**
|
||||||
* Returns the object as array.
|
* Returns the object as array.
|
||||||
*
|
*
|
||||||
|
* @param bool $ditch_items_when_mismatch Whether ditch items when mismatch or not.
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function to_array(): array {
|
public function to_array( bool $ditch_items_when_mismatch = true ): array {
|
||||||
$purchase_unit = array(
|
$purchase_unit = array(
|
||||||
'reference_id' => $this->reference_id(),
|
'reference_id' => $this->reference_id(),
|
||||||
'amount' => $this->amount()->to_array(),
|
'amount' => $this->amount()->to_array(),
|
||||||
|
@ -282,7 +284,7 @@ class PurchaseUnit {
|
||||||
$this->items()
|
$this->items()
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if ( $this->ditch_items_when_mismatch( $this->amount(), ...$this->items() ) ) {
|
if ( $ditch_items_when_mismatch && $this->ditch_items_when_mismatch( $this->amount(), ...$this->items() ) ) {
|
||||||
unset( $purchase_unit['items'] );
|
unset( $purchase_unit['items'] );
|
||||||
unset( $purchase_unit['amount']['breakdown'] );
|
unset( $purchase_unit['amount']['breakdown'] );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue