Track refunds
[MAILPOET-5485]
This commit is contained in:
@@ -419,6 +419,13 @@ class Hooks {
|
||||
10,
|
||||
1
|
||||
);
|
||||
|
||||
$this->wp->addAction(
|
||||
'woocommerce_order_refunded',
|
||||
[$this->hooksWooCommerce, 'trackRefund'],
|
||||
10,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
public function setupWooCommerceSubscriberEngagement() {
|
||||
|
@@ -115,6 +115,14 @@ class HooksWooCommerce {
|
||||
}
|
||||
}
|
||||
|
||||
public function trackRefund($id) {
|
||||
try {
|
||||
$this->woocommercePurchases->trackRefund($id);
|
||||
} catch (\Throwable $e) {
|
||||
$this->logError($e, 'WooCommerce Purchases Refund');
|
||||
}
|
||||
}
|
||||
|
||||
public function extendForm() {
|
||||
try {
|
||||
$this->subscriberRegistration->extendForm();
|
||||
|
@@ -52,13 +52,13 @@ class StatisticsWooCommercePurchasesRepository extends Repository {
|
||||
$click,
|
||||
$order->get_id(),
|
||||
$order->get_currency(),
|
||||
$order->get_total(),
|
||||
(float)$order->get_remaining_refund_amount(),
|
||||
$order->get_status()
|
||||
);
|
||||
$this->persist($statistics);
|
||||
} else {
|
||||
$statistics->setOrderCurrency($order->get_currency());
|
||||
$statistics->setOrderPriceTotal($order->get_total());
|
||||
$statistics->setOrderPriceTotal((float)$order->get_remaining_refund_amount());
|
||||
$statistics->setStatus($order->get_status());
|
||||
}
|
||||
$statistics->setSubscriber($click->getSubscriber());
|
||||
|
@@ -92,6 +92,14 @@ class WooCommercePurchases {
|
||||
}
|
||||
}
|
||||
|
||||
public function trackRefund($id) {
|
||||
$order = $this->woocommerceHelper->wcGetOrder($id);
|
||||
if (!$order instanceof WC_Order) {
|
||||
return;
|
||||
}
|
||||
$this->trackExistingStatistic($order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when a valid purchase statistic for an order was found.
|
||||
*
|
||||
|
@@ -158,7 +158,7 @@ class WooCommercePurchasesTest extends \MailPoetTest {
|
||||
expect($click->getId())->equals($click->getId());
|
||||
expect($purchaseStats[0]->getOrderId())->equals($orderMock->get_id());
|
||||
expect($purchaseStats[0]->getOrderCurrency())->equals($orderMock->get_currency());
|
||||
expect($purchaseStats[0]->getOrderPriceTotal())->equals($orderMock->get_total());
|
||||
expect($purchaseStats[0]->getOrderPriceTotal())->equals($orderMock->get_remaining_refund_amount());
|
||||
}
|
||||
|
||||
public function testItTracksPaymentForMultipleNewsletters() {
|
||||
@@ -544,13 +544,13 @@ class WooCommercePurchasesTest extends \MailPoetTest {
|
||||
->disableOriginalConstructor()
|
||||
->disableOriginalClone()
|
||||
->disableArgumentCloning()
|
||||
->setMethods(['get_id', 'get_date_created', 'get_billing_email', 'get_total', 'get_currency', 'get_status'])
|
||||
->setMethods(['get_id', 'get_date_created', 'get_billing_email', 'get_remaining_refund_amount', 'get_currency', 'get_status'])
|
||||
->getMock();
|
||||
|
||||
$mock->method('get_id')->willReturn($id);
|
||||
$mock->method('get_date_created')->willReturn($dateCreated ?? new DateTime());
|
||||
$mock->method('get_billing_email')->willReturn($email);
|
||||
$mock->method('get_total')->willReturn((string)$totalPrice);
|
||||
$mock->method('get_remaining_refund_amount')->willReturn((string)$totalPrice);
|
||||
$mock->method('get_currency')->willReturn('EUR');
|
||||
$mock->method('get_status')->willReturn($status);
|
||||
return $mock;
|
||||
|
Reference in New Issue
Block a user