function testBasic()
 {
     # Add AUTO_PAY_OFF to account to end up with unpaid invoices
     $this->account->addTags(array('00000000-0000-0000-0000-000000000001'), $this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $subscriptionData = new Killbill_Subscription();
     $subscriptionData->accountId = $this->account->accountId;
     $subscriptionData->productName = "Sports";
     $subscriptionData->productCategory = "BASE";
     $subscriptionData->billingPeriod = "MONTHLY";
     $subscriptionData->priceList = "DEFAULT";
     $subscriptionData->externalKey = $this->externalBundleId;
     $subscription = $subscriptionData->create($this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $this->assertEquals($subscription->accountId, $subscriptionData->accountId);
     $this->assertEquals($subscription->productName, $subscriptionData->productName);
     $this->assertEquals($subscription->productCategory, $subscriptionData->productCategory);
     $this->assertEquals($subscription->billingPeriod, $subscriptionData->billingPeriod);
     $this->assertEquals($subscription->externalKey, $subscriptionData->externalKey);
     # Move after trial
     $this->clock->addDays(31, $this->tenant->getTenantHeaders());
     $unpaidInvoices = $this->account->getInvoices(true, true, $this->tenant->getTenantHeaders());
     $this->assertEquals(count($unpaidInvoices), 1);
     # Remove the tag
     $this->account->deleteTags(array('00000000-0000-0000-0000-000000000001'), $this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     # processing unpaid invoices is asynchronous (bus event), so let's wait a bit before we check
     usleep(3000000);
     $unpaidInvoices = $this->account->getInvoices(true, true, $this->tenant->getTenantHeaders());
     $this->assertEmpty($unpaidInvoices);
     $allInvoices = $this->account->getInvoices(true, null, $this->tenant->getTenantHeaders());
     $this->assertEquals(count($allInvoices), 2);
 }
 function testBasic()
 {
     $subscriptionData = new Killbill_Subscription();
     $subscriptionData->accountId = $this->account->accountId;
     $subscriptionData->productName = "Sports";
     $subscriptionData->productCategory = "BASE";
     $subscriptionData->billingPeriod = "MONTHLY";
     $subscriptionData->priceList = "DEFAULT";
     $subscriptionData->externalKey = $this->externalBundleId;
     $subscription = $subscriptionData->create($this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $this->assertEquals($subscription->accountId, $subscriptionData->accountId);
     $this->assertEquals($subscription->productName, $subscriptionData->productName);
     $this->assertEquals($subscription->productCategory, $subscriptionData->productCategory);
     $this->assertEquals($subscription->billingPeriod, $subscriptionData->billingPeriod);
     $this->assertEquals($subscription->externalKey, $subscriptionData->externalKey);
     # Move clock after trials
     $this->clock->addDays(31, $this->tenant->getTenantHeaders());
     # Should see 2 invoices for account
     $invoices = $this->account->getInvoices(true, null, $this->tenant->getTenantHeaders());
     $this->assertEquals(2, count($invoices));
     # Retrieve each invoice by id
     $invoice = new Killbill_Invoice();
     $invoice->invoiceId = $invoices[0]->invoiceId;
     $invoice = $invoice->get(false, $this->tenant->getTenantHeaders());
     $this->assertNotEmpty($invoice);
     $this->assertNotEmpty($invoice->accountId);
     $this->assertNotEmpty($invoice->invoiceId);
     $this->assertNotEmpty($invoice->currency);
     $this->assertEquals($invoice->amount, 0);
     $this->assertEquals($invoice->balance, 0);
     $this->assertEmpty($invoice->items);
     $invoice = new Killbill_Invoice();
     $invoice->invoiceId = $invoices[1]->invoiceId;
     $invoice = $invoice->get(true, $this->tenant->getTenantHeaders());
     $this->assertNotEmpty($invoice);
     $this->assertNotEmpty($invoice->accountId);
     $this->assertNotEmpty($invoice->invoiceId);
     $this->assertNotEmpty($invoice->currency);
     $this->assertEquals($invoice->amount, 500);
     $this->assertEquals($invoice->balance, 0);
     $this->assertNotEmpty($invoice->items);
     $this->assertEquals(1, count($invoice->items));
 }
 public function testBundleWithTags()
 {
     $subscriptionData = new Killbill_Subscription();
     $subscriptionData->accountId = $this->account->accountId;
     $subscriptionData->productName = "Super";
     $subscriptionData->productCategory = "BASE";
     $subscriptionData->billingPeriod = "MONTHLY";
     $subscriptionData->priceList = "DEFAULT";
     $subscriptionData->externalKey = $this->externalBundleId;
     $subscriptionBase = $subscriptionData->create($this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $bundle = new Killbill_Bundle();
     $bundle->bundleId = $subscriptionBase->bundleId;
     $bundle = $bundle->get($this->tenant->getTenantHeaders());
     $tag1 = new Killbill_TagDefinition();
     $tag1->name = uniqid();
     $tag1->description = "This is super tag1";
     $tag1 = $tag1->create($this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $bundleTags = $bundle->addTags(array($tag1->id), $this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $this->assertEquals(1, count($bundleTags));
     $bundleTags = $bundle->getTags($this->tenant->getTenantHeaders());
     $this->assertEquals(1, count($bundleTags));
     $bundle->deleteTags(array($tag1->id), $this->user, $this->reason, $this->comment, $this->tenant->getTenantHeaders());
     $bundleTags = $bundle->getTags($this->tenant->getTenantHeaders());
     $this->assertEquals(0, count($bundleTags));
 }
Example #4
0
function iso8601($time = false)
{
    if (!$time) {
        $time = time();
    }
    return date("Y-m-d", $time);
}
$account = new Killbill_Account();
$account->accountId = $_SESSION['accountId'];
$account = $account->get($tenantHeaders);
for ($i = 1; $i <= $_POST['nb_plans']; $i++) {
    $quantity = intval($_POST['quantity_' . $i]);
    if ($quantity <= 0) {
        continue;
    }
    for ($j = 1; $j <= $quantity; $j++) {
        $externalBundleId = uniqid();
        // Associate a subscription
        $subscriptionData = new Killbill_Subscription();
        $subscriptionData->accountId = $account->accountId;
        $subscriptionData->externalKey = $externalBundleId;
        $subscriptionData->startDate = iso8601();
        $subscriptionData->productName = $_POST['product_' . $i];
        $subscriptionData->productCategory = $_POST['category_' . $i];
        $subscriptionData->billingPeriod = "MONTHLY";
        $subscriptionData->priceList = "DEFAULT";
        $subscription = $subscriptionData->createAndWait(true, "pierre", "PHP_TEST", "Test for " . $externalBundleId, $tenantHeaders);
    }
}
// Redirect the user to his subscriptions page
header('Location: subscriptions.php');