function Braintree_SubscriptionTest::testUpdate_canUpdateAddOnsAndDiscounts in Commerce Braintree 7
File
- braintree_php/
tests/ integration/ SubscriptionTest.php, line 777
Class
Code
function testUpdate_canUpdateAddOnsAndDiscounts() {
$oldCreditCard = Braintree_SubscriptionTestHelper::createCreditCard();
$plan = Braintree_SubscriptionTestHelper::addOnDiscountPlan();
$subscription = Braintree_Subscription::create(array(
'paymentMethodToken' => $oldCreditCard->token,
'price' => '54.99',
'planId' => $plan['id'],
))->subscription;
$result = Braintree_Subscription::update($subscription->id, array(
'addOns' => array(
'update' => array(
array(
'amount' => '99.99',
'existingId' => 'increase_10',
'quantity' => 99,
'numberOfBillingCycles' => 99,
),
array(
'amount' => '22.22',
'existingId' => 'increase_20',
'quantity' => 22,
'neverExpires' => true,
),
),
),
'discounts' => array(
'update' => array(
array(
'amount' => '33.33',
'existingId' => 'discount_11',
'quantity' => 33,
'numberOfBillingCycles' => 33,
),
),
),
));
$this
->assertTrue($result->success);
$subscription = $result->subscription;
$this
->assertEquals(2, sizeof($subscription->addOns));
$addOns = $subscription->addOns;
Braintree_SubscriptionTestHelper::sortModificationsById($addOns);
$this
->assertEquals($addOns[0]->id, "increase_10");
$this
->assertEquals($addOns[0]->amount, "99.99");
$this
->assertEquals($addOns[0]->neverExpires, false);
$this
->assertEquals($addOns[0]->numberOfBillingCycles, 99);
$this
->assertEquals($addOns[0]->quantity, 99);
$this
->assertEquals($addOns[1]->id, "increase_20");
$this
->assertEquals($addOns[1]->amount, "22.22");
$this
->assertEquals($addOns[1]->neverExpires, true);
$this
->assertEquals($addOns[1]->numberOfBillingCycles, null);
$this
->assertEquals($addOns[1]->quantity, 22);
$this
->assertEquals(2, sizeof($subscription->discounts));
$discounts = $subscription->discounts;
Braintree_SubscriptionTestHelper::sortModificationsById($discounts);
$this
->assertEquals($discounts[0]->id, "discount_11");
$this
->assertEquals($discounts[0]->amount, "33.33");
$this
->assertEquals($discounts[0]->neverExpires, false);
$this
->assertEquals($discounts[0]->numberOfBillingCycles, 33);
$this
->assertEquals($discounts[0]->quantity, 33);
}