Commit 34ddb380 authored by Mark Harding's avatar Mark Harding

(fix): all wires had the same subscription_id. introduce urns to solve front#298

parent 4c28ed54
No related merge requests found
Pipeline #69555251 passed with stages
in 9 minutes and 17 seconds
......@@ -54,4 +54,55 @@ class Subscriptions extends Cli\Controller implements Interfaces\CliControllerIn
$this->out("Done");
}
public function repair()
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
/** @var Manager $manager */
$manager = Di::_()->get('Payments\Subscriptions\Manager');
/** @var Queue $queue */
$subscriptions = Di::_()->get('Payments\Subscriptions\Iterator');
$subscriptions->setFrom(0)
->setPaymentMethod('tokens')
->setPlanId('wire');
foreach ($subscriptions as $subscription) {
$this->out("Subscription:`{$subscription->getId()}`");
if ($subscription->getId() === 'offchain') {
$this->out("Subscription:`{$subscription->getId()}` needs repairing");
$urn = "urn:subscription:" . implode('-', [
$subscription->getId(),
$subscription->getUser()->getGuid(),
$subscription->getEntity()->getGuid(),
]);
$this->out("Subscription:`{$subscription->getId()}` needs repairing to $urn");
$manager->setSubscription($subscription);
$manager->cancel();
$subscription->setId($urn);
$manager->setSubscription($subscription);
$manager->create();
}
if (strpos($subscription->getId(), '0x', 0) === 0) {
$this->out("Subscription:`{$subscription->getId()}` needs repairing");
$urn = "urn:subscription:" . implode('-', [
$subscription->getId(),
$subscription->getUser()->getGuid(),
$subscription->getEntity()->getGuid(),
]);
$this->out("Subscription:`{$subscription->getId()}` needs repairing to $urn");
$manager->setSubscription($subscription);
$manager->cancel();
$subscription->setId($urn);
$manager->setSubscription($subscription);
$manager->create();
}
}
$this->out("Done");
}
}
......@@ -14,6 +14,7 @@ use Cassandra\Varint;
use Minds\Core\Data\Cassandra\Client;
use Minds\Core\Data\Cassandra\Prepared\Custom;
use Minds\Core\Di\Di;
use Minds\Core\Util\BigNumber;
class Repository
{
......@@ -124,7 +125,7 @@ class Repository
->setPaymentMethod($row['payment_method'])
->setEntity((string) $row['entity_guid'])
->setUser((string) $row['user_guid'])
->setAmount($row['amount']->toDouble())
->setAmount((string) BigNumber::_($row['amount']))
->setInterval($row['interval'])
->setLastBilling($row['last_billing']->time())
->setNextBilling($row['next_billing']->time())
......
......@@ -76,8 +76,14 @@ class Manager
{
$this->cancelSubscription();
$urn = "urn:subscription:" . implode('-', [
$this->address, //offchain or onchain wallet
$this->sender->getGuid(),
$this->receiver->getGuid(),
]);
$subscription = (new Core\Payments\Subscriptions\Subscription())
->setId($this->address)
->setId($urn)
->setPlanId('wire')
->setPaymentMethod('tokens')
->setAmount($this->amount)
......@@ -110,4 +116,4 @@ class Manager
// Cancel old subscription first
$this->subscriptionsManager->cancel();
}
}
\ No newline at end of file
}
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