nstanceof WC_Product ? $this->prepare_sku($product->get_sku()) : '', $product instanceof WC_Product && $product->is_virtual() ? Item::DIGITAL_GOODS : Item::PHYSICAL_GOODS, $product instanceof WC_Product ? $product->get_permalink() : '', $image[0] ?? ''); } /** * Creates an Item based off a WooCommerce Fee Item. * * @param \WC_Order_Item_Fee $item The WooCommerce order item. * @param \WC_Order $order The WooCommerce order. * * @return Item */ private function from_wc_order_fee(\WC_Order_Item_Fee $item, \WC_Order $order): Item { return new Item($this->prepare_item_string($item->get_name()), new Money((float) $item->get_amount(), $order->get_currency()), $item->get_quantity(), '', null); } /** * Creates an Item based off a PayPal response. * * @param \stdClass $data The JSON object. * * @return Item * @throws RuntimeException When JSON object is malformed. */ public function from_paypal_response(\stdClass $data): Item { if (!isset($data->name)) { throw new RuntimeException(__('No name for item given', 'woocommerce-paypal-payments')); } if (!isset($data->quantity) || !is_numeric($data->quantity)) { throw new RuntimeException(__('No quantity for item given', 'woocommerce-paypal-payments')); } if (!isset($data->unit_amount->value) || !isset($data->unit_amount->currency_code)) { throw new RuntimeException(__('No money values for item given', 'woocommerce-paypal-payments')); } $unit_amount = new Money((float) $data->unit_amount->value, $data->unit_amount->currency_code); $description = isset($data->description) ? $data->description : ''; $tax = isset($data->tax) ? new Money((float) $data->tax->value, $data->tax->currency_code) : null; $sku = isset($data->sku) ? $data->sku : ''; $category = isset($data->category) ? $data->category : 'PHYSICAL_GOODS'; $url = isset($data->url) ? $data->url : ''; $image_url = isset($data->image_url) ? $data->image_url : ''; return new Item($data->name, $unit_amount, (int) $data->quantity, $description, $tax, $sku, $category, $url, $image_url); } }