Track refunds
[MAILPOET-5485]
This commit is contained in:
@@ -419,6 +419,13 @@ class Hooks {
|
|||||||
10,
|
10,
|
||||||
1
|
1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->wp->addAction(
|
||||||
|
'woocommerce_order_refunded',
|
||||||
|
[$this->hooksWooCommerce, 'trackRefund'],
|
||||||
|
10,
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setupWooCommerceSubscriberEngagement() {
|
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() {
|
public function extendForm() {
|
||||||
try {
|
try {
|
||||||
$this->subscriberRegistration->extendForm();
|
$this->subscriberRegistration->extendForm();
|
||||||
|
@@ -52,13 +52,13 @@ class StatisticsWooCommercePurchasesRepository extends Repository {
|
|||||||
$click,
|
$click,
|
||||||
$order->get_id(),
|
$order->get_id(),
|
||||||
$order->get_currency(),
|
$order->get_currency(),
|
||||||
$order->get_total(),
|
(float)$order->get_remaining_refund_amount(),
|
||||||
$order->get_status()
|
$order->get_status()
|
||||||
);
|
);
|
||||||
$this->persist($statistics);
|
$this->persist($statistics);
|
||||||
} else {
|
} else {
|
||||||
$statistics->setOrderCurrency($order->get_currency());
|
$statistics->setOrderCurrency($order->get_currency());
|
||||||
$statistics->setOrderPriceTotal($order->get_total());
|
$statistics->setOrderPriceTotal((float)$order->get_remaining_refund_amount());
|
||||||
$statistics->setStatus($order->get_status());
|
$statistics->setStatus($order->get_status());
|
||||||
}
|
}
|
||||||
$statistics->setSubscriber($click->getSubscriber());
|
$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.
|
* 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($click->getId())->equals($click->getId());
|
||||||
expect($purchaseStats[0]->getOrderId())->equals($orderMock->get_id());
|
expect($purchaseStats[0]->getOrderId())->equals($orderMock->get_id());
|
||||||
expect($purchaseStats[0]->getOrderCurrency())->equals($orderMock->get_currency());
|
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() {
|
public function testItTracksPaymentForMultipleNewsletters() {
|
||||||
@@ -544,13 +544,13 @@ class WooCommercePurchasesTest extends \MailPoetTest {
|
|||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->disableOriginalClone()
|
->disableOriginalClone()
|
||||||
->disableArgumentCloning()
|
->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();
|
->getMock();
|
||||||
|
|
||||||
$mock->method('get_id')->willReturn($id);
|
$mock->method('get_id')->willReturn($id);
|
||||||
$mock->method('get_date_created')->willReturn($dateCreated ?? new DateTime());
|
$mock->method('get_date_created')->willReturn($dateCreated ?? new DateTime());
|
||||||
$mock->method('get_billing_email')->willReturn($email);
|
$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_currency')->willReturn('EUR');
|
||||||
$mock->method('get_status')->willReturn($status);
|
$mock->method('get_status')->willReturn($status);
|
||||||
return $mock;
|
return $mock;
|
||||||
|
Reference in New Issue
Block a user