Skip to content

Commit

Permalink
rename refund transaction id constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Paun committed Jan 4, 2024
1 parent 77bcca1 commit f05ac42
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion changelog/add-transaction-id-to-refund-endpoint
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Significance: minor
Type: add

Expose WooCommerce transaction id for a refund on refund API endpoint
Expose the refund transaction ID in WooCommerce Order Refund API
2 changes: 1 addition & 1 deletion includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ static function ( $refund ) use ( $refund_amount ) {
$wc_last_refund = WC_Payments_Utils::get_last_refund_from_order_id( $order_id );
if ( $wc_last_refund ) {
$this->order_service->set_wcpay_refund_id_for_order( $wc_last_refund, $refund['id'] );
$this->order_service->set_wcpay_transaction_id_for_order( $wc_last_refund, $refund['balance_transaction'] );
$this->order_service->set_wcpay_refund_transaction_id_for_order( $wc_last_refund, $refund['balance_transaction'] );
$wc_last_refund->save_meta_data();
}

Expand Down
10 changes: 5 additions & 5 deletions includes/class-wc-payments-order-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class WC_Payments_Order_Service {
*
* @const string
*/
const WCPAY_TRANSACTION_ID_META_KEY = '_refund_transaction_id';
const WCPAY_REFUND_TRANSACTION_ID_META_KEY = '_wcpay_refund_transaction_id';

/**
* Meta key used to store WCPay refund status.
Expand Down Expand Up @@ -661,14 +661,14 @@ public function set_wcpay_refund_id_for_order( $order, $wcpay_refund_id ) {
/**
* Set the payment metadata for refund transaction id.
*
* @param mixed $order The order.
* @param string $wcpay_transaction_id The value to be set.
* @param WC_Order_Refund $order The order.
* @param string $wcpay_transaction_id The value to be set.
*
* @throws Order_Not_Found_Exception
*/
public function set_wcpay_transaction_id_for_order( $order, $wcpay_transaction_id ) {
public function set_wcpay_refund_transaction_id_for_order( WC_Order_Refund $order, string $wcpay_transaction_id ) {
$order = $this->get_order( $order );
$order->update_meta_data( self::WCPAY_TRANSACTION_ID_META_KEY, $wcpay_transaction_id );
$order->update_meta_data( self::WCPAY_REFUND_TRANSACTION_ID_META_KEY, $wcpay_transaction_id );
$order->save_meta_data();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test-class-wc-payments-order-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,10 @@ public function test_set_wcpay_refund_id() {
$this->assertEquals( $this->order->get_meta( '_wcpay_refund_id', true ), $wcpay_refund_id );
}

public function set_wcpay_transaction_id_for_order() {
public function set_wcpay_refund_transaction_id_for_order() {
$wcpay_refund_transaction_id = 'txn_mock';
$this->order_service->set_wcpay_transaction_id_for_order( $this->order, $wcpay_refund_transaction_id );
$this->assertSame( $this->order->get_meta( WC_Payments_Order_Service::WCPAY_TRANSACTION_ID_META_KEY, true ), $wcpay_refund_transaction_id );
$this->order_service->set_wcpay_refund_transaction_id_for_order( $this->order, $wcpay_refund_transaction_id );
$this->assertSame( $this->order->get_meta( WC_Payments_Order_Service::WCPAY_REFUND_TRANSACTION_ID_META_KEY, true ), $wcpay_refund_transaction_id );
}

public function test_get_wcpay_refund_id() {
Expand Down

0 comments on commit f05ac42

Please sign in to comment.