Commit d85a52eb authored by Olivia Madrid's avatar Olivia Madrid

(feat): wire emails support multiple currencies

1 merge request!287WIP: (feat): Wire email templates support multiple currencies
Pipeline #73398506 failed with stages
in 4 minutes and 59 seconds
<?php
$wireUrl = "{$vars['site_url']}wallet/tokens/transactions/{$vars['contract']}?{$vars['tracking']}";
$avatarUrl = "{$vars['sender']->getIconUrl()}";
$wireDate = date('M d, Y', ($vars['timestamp']));
$wireDate = date('M d, Y', ($vars['timestamp']));
$amount = number_format($vars['amount'], 2);
?>
<table cellspacing="8" cellpadding="8" border="0" width="600" align="center">
......@@ -19,7 +19,7 @@
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>@<?php echo $vars['sender']->get('name'); ?> wired you</h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?> tokens
<?php echo $wireDate; ?>; +<?php echo $amount ?>
</p>
</td>
</tr>
......@@ -36,7 +36,7 @@
<tr>
<td>
<p <?php echo $emailStyles->getStyles('m-clear', 'm-fonts'); ?>>
For any issues, including the recipient not receiving tokens, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
For any issues, including the recipient not receiving their wire, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
</p>
</td>
</tr>
......
<?php
$wireUrl = "{$vars['site_url']}wallet/tokens/transactions/{$vars['contract']}?{$vars['tracking']}";
$avatarUrl = "{$vars['receiver']->getIconUrl()}";
$wireDate = date('M d, Y', ($vars['timestamp']));
$wireDate = date('M d, Y', ($vars['timestamp']));
$amount = number_format($vars['amount'], 2);
?>
<table cellspacing="8" cellpadding="8" border="0" width="600" align="center">
......@@ -19,7 +19,7 @@
<h4 <?php echo $emailStyles->getStyles('m-clear', 'm-fonts', 'm-header'); ?>>You wired @<?php echo $vars['receiver']->get('name'); ?></h4>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>Transfer Date and Amount:</p>
<p <?php echo $emailStyles->getStyles('m-fonts', 'm-subtitle', 'm-clear'); ?>>
<?php echo $wireDate; ?>; +<?php echo $amount ?> tokens
<?php echo $wireDate; ?>; +<?php echo $amount ?>
</p>
</td>
</tr>
......@@ -36,7 +36,7 @@
<tr>
<td>
<p <?php echo $emailStyles->getStyles('m-clear', 'm-fonts'); ?>>
For any issues, including the recipient not receiving tokens, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
For any issues, including the recipient not receiving their wire, please contact us at <a href="mailto:info@minds.com">info@minds.com</a>.
</p>
</td>
</tr>
......
......@@ -40,7 +40,6 @@ class WireReceived extends EmailCampaign
];
$timestamp = gettype($this->wire->getTimestamp()) === 'object' ? $this->wire->getTimestamp()->time() : $this->wire->getTimestamp();
$amount = $this->wire->getMethod() === 'tokens' ? BigNumber::fromPlain($this->wire->getAmount(), 18)->toDouble() : $this->wire->getAmount();
$contract = $this->wire->getMethod() === 'onchain' ? 'wire' : 'offchain:wire';
$this->template->setTemplate('default.tpl');
......@@ -50,7 +49,7 @@ class WireReceived extends EmailCampaign
$this->template->set('email', $this->user->getEmail());
$this->template->set('guid', $this->user->getGUID());
$this->template->set('timestamp', $timestamp);
$this->template->set('amount', $amount);
$this->template->set('amount', $this->getAmountString($this->wire));
$this->template->set('sender', $this->wire->getSender());
$this->template->set('contract', $contract);
$this->template->set('campaign', $this->campaign);
......@@ -73,4 +72,21 @@ class WireReceived extends EmailCampaign
$this->mailer->queue($this->build());
}
}
private function getAmountString($wire)
{
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
if ($wire->getMethod() === 'usd') {
$amount = $amount / 100;
}
return "$amount $currency";
}
}
......@@ -40,8 +40,6 @@ class WireSent extends EmailCampaign
];
$timestamp = gettype($this->wire->getTimestamp()) === 'object' ? $this->wire->getTimestamp()->time() : $this->wire->getTimestamp();
// $amount = $this->wire->getMethod() === 'tokens' ? BigNumber::fromPlain($this->wire->getAmount(), 18)->toDouble() : $this->wire->getAmount();
$amount = $this->getAmountString($this->wire);
$contract = $this->wire->getMethod() === 'onchain' ? 'wire' : 'offchain:wire';
$this->template->setTemplate('default.tpl');
......@@ -51,7 +49,7 @@ class WireSent extends EmailCampaign
$this->template->set('email', $this->user->getEmail());
$this->template->set('guid', $this->user->getGUID());
$this->template->set('timestamp', $timestamp);
$this->template->set('amount', $amount);
$this->template->set('amount', $this->getAmountString($this->wire));
$this->template->set('receiver', $this->wire->getReceiver());
$this->template->set('sender', $this->wire->getSender());
$this->template->set('contract', $contract);
......@@ -76,13 +74,12 @@ class WireSent extends EmailCampaign
}
}
private function getAmountString($wire)
{
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount > 1 ? 'tokens' : 'token';
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
......
......@@ -101,7 +101,7 @@ class WireNotification implements Interfaces\QueueRunner
$amount = $wire->getAmount();
if ($wire->getMethod() === 'tokens') {
$amount = BigNumber::fromPlain($wire->getAmount(), 18)->toDouble();
$currency = $amount > 1 ? 'tokens' : 'token';
$currency = $amount === 1 ? 'token' : 'tokens';
} else {
$currency = strtoupper($wire->getMethod());
}
......
......@@ -67,6 +67,8 @@ class WireReceivedSpec extends ObjectBehavior
public function it_should_send_a_wire_received_email_tokens()
{
$this->wire->setMethod('tokens');
$this->wire->setAmount(2000000000000000);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
......@@ -79,7 +81,39 @@ class WireReceivedSpec extends ObjectBehavior
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['amount']->shouldEqual(BigNumber::fromPlain(10, 18)->toDouble());
$data['amount']->shouldEqual('0.002 tokens');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
->setUserGuid($this->receiverGUID)
->setCampaign('when')
->setTopic('wire_received')
->setValue(true);
$this->manager->isSubscribed($testEmailSubscription)->shouldBeCalled()->willReturn(true);
$this->send();
}
public function it_should_send_a_wire_received_email_eth()
{
$this->wire->setMethod('eth');
$this->wire->setAmount(7);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
$this->setWire($this->wire);
$this->setSuggestions($this->mockSuggestions());
$message = $this->build();
$message->getSubject()->shouldEqual('You received a wire');
$to = $message->getTo()[0]['name']->shouldEqual($this->receiverName);
$to = $message->getTo()[0]['email']->shouldEqual($this->receiverEmail);
$data = $this->getTemplate()->getData();
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['amount']->shouldEqual('7 ETH');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
......@@ -92,9 +126,10 @@ class WireReceivedSpec extends ObjectBehavior
$this->send();
}
public function it_should_send_a_wire_received_email_onchain()
public function it_should_send_a_wire_received_email_usd()
{
$this->wire->setMethod('onchain');
$this->wire->setMethod('usd');
$this->wire->setAmount(500);
$this->getCampaign()->shouldEqual('when');
$this->getTopic()->shouldEqual('wire_received');
$this->setUser($this->receiver);
......@@ -108,8 +143,8 @@ class WireReceivedSpec extends ObjectBehavior
$data['guid']->shouldEqual($this->receiverGUID);
$data['email']->shouldEqual($this->receiverEmail);
$data['username']->shouldEqual($this->receiverUsername);
$data['contract']->shouldEqual('wire');
$data['amount']->shouldEqual(10);
$data['amount']->shouldEqual('5 USD');
$this->mailer->queue(Argument::any())->shouldBeCalled();
$testEmailSubscription = (new EmailSubscription())
......@@ -122,6 +157,36 @@ class WireReceivedSpec extends ObjectBehavior
$this->send();
}
// public function it_should_send_a_wire_received_email_onchain()
// {
// $this->wire->setMethod('onchain');
// $this->getCampaign()->shouldEqual('when');
// $this->getTopic()->shouldEqual('wire_received');
// $this->setUser($this->receiver);
// $this->setWire($this->wire);
// $this->setSuggestions($this->mockSuggestions());
// $message = $this->build();
// $message->getSubject()->shouldEqual('You received a wire');
// $to = $message->getTo()[0]['name']->shouldEqual($this->receiverName);
// $to = $message->getTo()[0]['email']->shouldEqual($this->receiverEmail);
// $data = $this->getTemplate()->getData();
// $data['guid']->shouldEqual($this->receiverGUID);
// $data['email']->shouldEqual($this->receiverEmail);
// $data['username']->shouldEqual($this->receiverUsername);
// $data['contract']->shouldEqual('wire');
// $data['amount']->shouldEqual('2000000000000000 ONCHAIN');
// $this->mailer->queue(Argument::any())->shouldBeCalled();
// $testEmailSubscription = (new EmailSubscription())
// ->setUserGuid($this->receiverGUID)
// ->setCampaign('when')
// ->setTopic('wire_received')
// ->setValue(true);
// $this->manager->isSubscribed($testEmailSubscription)->shouldBeCalled()->willReturn(true);
// $this->send();
// }
public function it_should_not_send_unsubscribed()
{
$this->getCampaign()->shouldEqual('when');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment