/** * Capture full shipping address in the case of a $0 order, using the "login app" version of the API. * * @param int $order_id * * @throws Exception */ function capture_shipping_address_for_zero_order_total($order_id) { $order = new WC_Order($order_id); // Complete address data is only available without a confirmed order if we're using the login app // See the "Getting the Shipping Address" section here: https://payments.amazon.com/documentation/lpwa/201749990 if ($order->get_total() > 0 || empty($this->reference_id) || 'yes' !== $this->settings['enable_login_app'] || empty($this->access_token)) { return; } // Get FULL address details and save them to the order $order_details = $this->gateway->get_amazon_order_details($order_id, $this->reference_id); if ($order_details) { $this->store_order_address_details($order_id, $order_details); } }
/** * Retrieve full details from the order using 'GetBillingAgreementDetails' (if it contains a subscription). * * @param string $amazon_reference_id * * @return bool|object Boolean false on failure, object of OrderReferenceDetails on success. */ function get_amazon_order_details($amazon_reference_id) { if (!WC_Subscriptions_Cart::cart_contains_subscription()) { return parent::get_amazon_order_details($amazon_reference_id); } $response = WC_Amazon_Payments_Advanced_API::request(array('Action' => 'GetBillingAgreementDetails', 'AmazonBillingAgreementId' => $amazon_reference_id)); if (!is_wp_error($response) && isset($response->GetBillingAgreementDetailsResult->BillingAgreementDetails)) { return $response->GetBillingAgreementDetailsResult->BillingAgreementDetails; } return false; }