function testCreate_whenSuccessful()
 {
     $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
     $plan = Braintree_SubscriptionTestHelper::triallessPlan();
     $result = Braintree_Subscription::create(array('paymentMethodToken' => $creditCard->token, 'planId' => $plan['id']));
     Braintree_TestHelper::assertPrintable($result);
     $this->assertTrue($result->success);
     $subscription = $result->subscription;
     $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
     $this->assertEquals(0, $subscription->failureCount);
     $this->assertEquals($plan['id'], $subscription->planId);
     $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $subscription->merchantAccountId);
     $this->assertEquals(Braintree_Subscription::ACTIVE, $subscription->status);
     $this->assertEquals('12.34', $subscription->nextBillAmount);
     $this->assertEquals('12.34', $subscription->nextBillingPeriodAmount);
     $this->assertEquals('0.00', $subscription->balance);
     $this->assertEquals(1, $subscription->currentBillingCycle);
     $this->assertInstanceOf('DateTime', $subscription->firstBillingDate);
     $this->assertInstanceOf('DateTime', $subscription->nextBillingDate);
     $this->assertInstanceOf('DateTime', $subscription->billingPeriodStartDate);
     $this->assertInstanceOf('DateTime', $subscription->billingPeriodEndDate);
     $this->assertInstanceOf('DateTime', $subscription->paidThroughDate);
     $this->assertInstanceOf('DateTime', $subscription->updatedAt);
     $this->assertInstanceOf('DateTime', $subscription->createdAt);
 }
 function testGatewayCreate_whenSuccessful()
 {
     $creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
     $plan = Braintree_SubscriptionTestHelper::triallessPlan();
     $gateway = new Braintree_Gateway(array('environment' => 'development', 'merchantId' => 'integration_merchant_id', 'publicKey' => 'integration_public_key', 'privateKey' => 'integration_private_key'));
     $result = $gateway->subscription()->create(array('paymentMethodToken' => $creditCard->token, 'planId' => $plan['id']));
     Braintree_TestHelper::assertPrintable($result);
     $this->assertTrue($result->success);
     $subscription = $result->subscription;
     $this->assertEquals($creditCard->token, $subscription->paymentMethodToken);
     $this->assertEquals(0, $subscription->failureCount);
     $this->assertEquals($plan['id'], $subscription->planId);
     $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $subscription->merchantAccountId);
     $this->assertEquals(Braintree_Subscription::ACTIVE, $subscription->status);
 }
 function testUpdate_withCardVerification()
 {
     $customer = Braintree_Customer::createNoValidate();
     $initialCreditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
     $result = Braintree_CreditCard::update($initialCreditCard->token, array('billingAddress' => array('region' => 'IL'), 'options' => array('verifyCard' => true)));
     $this->assertFalse($result->success);
     $this->assertEquals(Braintree_Result_CreditCardVerification::PROCESSOR_DECLINED, $result->creditCardVerification->status);
     $this->assertEquals('2000', $result->creditCardVerification->processorResponseCode);
     $this->assertEquals('Do Not Honor', $result->creditCardVerification->processorResponseText);
     $this->assertEquals('I', $result->creditCardVerification->cvvResponseCode);
     $this->assertEquals(null, $result->creditCardVerification->avsErrorResponseCode);
     $this->assertEquals('I', $result->creditCardVerification->avsPostalCodeResponseCode);
     $this->assertEquals('I', $result->creditCardVerification->avsStreetAddressResponseCode);
     $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $result->creditCardVerification->merchantAccountId);
 }
 function testCredit_withoutMerchantAccountIdFallsBackToDefault()
 {
     $result = Braintree_Transaction::credit(array('amount' => '100.00', 'creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12')));
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals(Braintree_TestHelper::defaultMerchantAccountId(), $transaction->merchantAccountId);
 }