mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
* feat: HPOS support added. * fix: Refund connections and connection permission fixed * chore: Linter compliance met. * devops: CI script updated. * devops: CI script updated. * fix: Syntax error fixed. * devops: CI script updated. * devops: CI script updated. * devops: CI script updated. * chore: PHPStan fixes started. * chore: linter compliance met. * chore: fix scanning and type-hinting for non-stubbed classes * dev: refactor Order model around WC_Abstract_Order * chore: update dev deps * devops: PHPStan and Linter compliance met. * devops: HPOS test temporarily suppressed. --------- Co-authored-by: David Levine <david@axepress.dev>
79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
use GraphQLRelay\Relay;
|
|
|
|
class RefundHelper extends WCG_Helper {
|
|
public function __construct() {
|
|
$this->node_type = 'shop_order_refund';
|
|
|
|
parent::__construct();
|
|
}
|
|
|
|
public function to_relay_id( $id ) {
|
|
return Relay::toGlobalId( 'order', $id );
|
|
}
|
|
|
|
public function create( $order, $args = array() ) {
|
|
$order = new WC_Order( $order );
|
|
if ( empty( $order ) ) {
|
|
return false;
|
|
}
|
|
|
|
$refund = wc_create_refund(
|
|
array_merge(
|
|
array(
|
|
'amount' => floatval( $order->get_total() ),
|
|
'order_id' => $order->get_id(),
|
|
'reason' => 'defective',
|
|
'refund_payment' => false,
|
|
'restock_items' => false,
|
|
),
|
|
$args
|
|
)
|
|
);
|
|
|
|
if ( ! empty( $refund ) && ! empty( $args['meta_data'] ) ) {
|
|
$refund->set_meta_data( $args['meta_data'] );
|
|
$refund->save_meta_data();
|
|
}
|
|
|
|
return ! empty( $refund ) ? $refund->get_id() : 0;
|
|
}
|
|
|
|
public function print_query( $id ) {
|
|
$data = new WC_Order_Refund( $id );
|
|
if ( ! $data ) {
|
|
return null;
|
|
}
|
|
|
|
return array(
|
|
'id' => $this->to_relay_id( $id ),
|
|
'databaseId' => $data->get_id(),
|
|
'title' => $data->get_post_title(),
|
|
'reason' => $data->get_reason(),
|
|
'amount' => $data->get_amount(),
|
|
'refundedBy' => array(
|
|
'id' => Relay::toGlobalId( 'user', $data->get_refunded_by() )
|
|
),
|
|
'date' => $data->get_date_modified(),
|
|
);
|
|
}
|
|
|
|
public function print_failed_query( $id ) {
|
|
$data = new WC_Order_Refund( $id );
|
|
if ( ! $data ) {
|
|
return null;
|
|
}
|
|
|
|
return array(
|
|
'id' => $this->to_relay_id( $id ),
|
|
'databaseId' => $data->get_id(),
|
|
'title' => null,
|
|
'reason' => null,
|
|
'amount' => null,
|
|
'refundedBy' => null,
|
|
'date' => null,
|
|
);
|
|
}
|
|
}
|