square_api = $api_client->getRefundsApi(); } /** * Sets the data for refund a payment. * * @since 2.2.0 * * @param \WC_Order $order order object * @param array $refund_data array of data required for a refund. */ public function set_refund_data( \WC_Order $order, $refund_data = array() ) { $this->square_api_method = 'refundPayment'; // The refund objects are sorted by date DESC, so the last one created will be at the start of the array $refunds = $order->get_refunds(); $refund_obj = $refunds[0]; $refund_amount = empty( $refund_data['amount'] ) ? $order->refund->amount : $refund_data['amount']; $tender_id = empty( $refund_data['tender_id'] ) ? $order->refund->tender_id : $refund_data['tender_id']; $payment_type = empty( $refund_data['payment_type'] ) ? '' : "-{$refund_data['payment_type']}"; $this->square_request = new RefundPaymentRequest( wc_square()->get_idempotency_key( $order->get_id() . ':' . $refund_obj->get_id() . $payment_type ), Money_Utility::amount_to_money( $refund_amount, $order->get_currency() ) ); $this->square_request->setPaymentId( $tender_id ); $this->square_request->setReason( $order->refund->reason ); $this->square_api_args = array( $this->square_request ); } }