Example #1
0
 public function testAll_returnsAllAddOns()
 {
     $newId = strval(rand());
     $addOnParams = ["amount" => "100.00", "description" => "some description", "id" => $newId, "kind" => "add_on", "name" => "php_add_on", "neverExpires" => "false", "numberOfBillingCycles" => "1"];
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . "/modifications/create_modification_for_tests";
     $http->post($path, ["modification" => $addOnParams]);
     $addOns = Braintree\AddOn::all();
     foreach ($addOns as $addOn) {
         if ($addOn->id == $newId) {
             $actualAddOn = $addOn;
         }
     }
     $this->assertNotNull($actualAddOn);
     $this->assertEquals($addOnParams["amount"], $actualAddOn->amount);
     $this->assertEquals($addOnParams["description"], $actualAddOn->description);
     $this->assertEquals($addOnParams["id"], $actualAddOn->id);
     $this->assertEquals($addOnParams["kind"], $actualAddOn->kind);
     $this->assertEquals($addOnParams["name"], $actualAddOn->name);
     $this->assertFalse($actualAddOn->neverExpires);
     $this->assertEquals($addOnParams["numberOfBillingCycles"], $actualAddOn->numberOfBillingCycles);
 }
 /**
  * @param string $plan_id
  * @param array $addOns
  * @param array $discounts
  * @param array $removeAddOns
  * @param array $removeDiscounts
  * @return mixed
  */
 public function getPlanSummary($plan_id, $addOns = [], $discounts = [], $removeAddOns = [], $removeDiscounts = [])
 {
     $summary = [];
     $plans = Braintree_Plan::all();
     foreach ($plans as $plan) {
         if ($plan->id == $plan_id) {
             $summary = [];
             $summary['price'] = $plan->price;
             $summary['summary'] = $plan->price;
             //add all default add-ons
             if (!empty($plan->addOns)) {
                 foreach ($plan->addOns as $planAddOn) {
                     if (!in_array($planAddOn->id, $removeAddOns)) {
                         $summary['addOns'][] = ['name' => $planAddOn->name, 'description' => $planAddOn->description, 'amount' => $planAddOn->amount];
                         $summary['summary'] += $planAddOn->amount;
                     }
                 }
             }
             //add all default discounts
             if (!empty($plan->discounts)) {
                 foreach ($plan->discounts as $planDiscount) {
                     if (!in_array($planDiscount->id, $removeDiscounts)) {
                         $summary['discounts'][] = ['name' => $planDiscount->name, 'description' => $planDiscount->description, 'amount' => $planDiscount->amount];
                         $summary['summary'] -= $planDiscount->amount;
                     }
                 }
             }
             break;
         }
     }
     //add all manually added add-ons
     $SystemAddOns = Braintree_AddOn::all();
     foreach ($addOns as $addOn) {
         foreach ($SystemAddOns as $SystemAddOn) {
             if ($SystemAddOn->id == $addOn) {
                 $summary['addOns'][] = ['name' => $SystemAddOn->name, 'description' => $SystemAddOn->description, 'amount' => $SystemAddOn->amount];
                 $summary['summary'] += $SystemAddOn->amount;
             }
         }
     }
     //add all manually added discounts
     $SystemDiscounts = Braintree_Discount::all();
     foreach ($discounts as $discount) {
         foreach ($SystemDiscounts as $SystemDiscount) {
             if ($SystemDiscount->id == $discount) {
                 $summary['discounts'][] = ['name' => $SystemDiscount->name, 'description' => $SystemDiscount->description, 'amount' => $SystemDiscount->amount];
                 $summary['summary'] -= $SystemDiscount->amount;
             }
         }
     }
     return $summary;
 }
Example #3
0
 public function testToString()
 {
     $addOnParams = ["amount" => "100.00", "description" => "some description", "id" => "1", "kind" => "add_on", "name" => "php_add_on", "neverExpires" => "false", "numberOfBillingCycles" => "1"];
     $addOn = Braintree\AddOn::factory($addOnParams);
     $this->assertEquals("Braintree\\AddOn[amount=100.00, description=some description, id=1, kind=add_on, name=php_add_on, neverExpires=false, numberOfBillingCycles=1]", (string) $addOn);
 }