/**
  * Get customer details from amazon
  */
 public function get_customer_details()
 {
     try {
         // Update order reference with amounts
         $amazon = new WC_Gateway_Amazon_Payments_Advanced();
         $response = $amazon->api_request(array('Action' => 'GetOrderReferenceDetails', 'AmazonOrderReferenceId' => $this->reference_id));
         if (is_wp_error($response)) {
             throw new Exception($response->get_error_message());
         }
         if (!isset($response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'])) {
             return;
         }
         $address = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails']['Destination']['PhysicalDestination'];
         if (!empty($address['CountryCode'])) {
             WC()->customer->set_country($address['CountryCode']);
             WC()->customer->set_shipping_country($address['CountryCode']);
         }
         if (!empty($address['StateOrRegion'])) {
             WC()->customer->set_state($address['StateOrRegion']);
             WC()->customer->set_shipping_state($address['StateOrRegion']);
         }
         if (!empty($address['PostalCode'])) {
             WC()->customer->set_postcode($address['PostalCode']);
             WC()->customer->set_shipping_postcode($address['PostalCode']);
         }
         if (!empty($address['City'])) {
             WC()->customer->set_city($address['City']);
             WC()->customer->set_shipping_city($address['City']);
         }
     } catch (Exception $e) {
         wc_add_notice(__('Error:', 'woocommerce-gateway-amazon-payments-advanced') . ' ' . $e->getMessage(), 'error');
         return;
     }
 }
 /**
  * Refund a payment
  * @param  int $order_id
  * @param  string $capture_id
  * @param  float $amount
  */
 public function refund_payment($order_id, $capture_id, $amount, $note)
 {
     $order = new WC_Order($order_id);
     if ($order->payment_method == 'amazon_payments_advanced') {
         if ('US' == WC()->countries->get_base_country() && $amount > $order->get_total()) {
             $order->add_order_note(__('Unable to refund funds via amazon:', 'woocommerce-gateway-amazon-payments-advanced') . ' ' . __('Refund amount is greater than order total.', 'woocommerce-gateway-amazon-payments-advanced'));
             return;
         } elseif ($amount > min($order->get_total() * 1.15, $order->get_total() + 75)) {
             $order->add_order_note(__('Unable to refund funds via amazon:', 'woocommerce-gateway-amazon-payments-advanced') . ' ' . __('Refund amount is greater than the max refund amount.', 'woocommerce-gateway-amazon-payments-advanced'));
             return;
         }
         $amazon = new WC_Gateway_Amazon_Payments_Advanced();
         $response = $amazon->api_request(array('Action' => 'Refund', 'AmazonCaptureId' => $capture_id, 'RefundReferenceId' => $order->id . '-' . current_time('timestamp', true), 'RefundAmount.Amount' => $amount, 'RefundAmount.CurrencyCode' => strtoupper(get_woocommerce_currency()), 'SellerRefundNote' => $note));
         if (is_wp_error($response)) {
             $order->add_order_note(__('Unable to refund funds via amazon:', 'woocommerce-gateway-amazon-payments-advanced') . ' ' . $response->get_error_message());
         } elseif (isset($response['Error']['Message'])) {
             $order->add_order_note($response['Error']['Message']);
         } else {
             $refund_id = $response['RefundResult']['RefundDetails']['AmazonRefundId'];
             $order->add_order_note(sprintf(__('Refunded %s (%s)', 'woocommerce-gateway-amazon-payments-advanced'), woocommerce_price($amount), $note));
             add_post_meta($order_id, 'amazon_refund_id', $refund_id);
         }
     }
 }