/**
  * {@inheritdoc}
  */
 public function find($code)
 {
     $discounts = BraintreeDiscount::all();
     foreach ($discounts as $discount) {
         if ($discount->id === $code) {
             return $this->toCoupon($discount);
         }
     }
 }
 /**
  * Find Braintree discount object by id.
  *
  * @param int $id
  * @return \Braintree\Discount
  * @throws \Exception
  */
 public function findCouponById($id)
 {
     $braintreeCoupons = BraintreeDiscount::all();
     $coupon = null;
     foreach ($braintreeCoupons as $braintreeCoupon) {
         if ($braintreeCoupon->id == $this->coupon) {
             return $braintreeCoupon;
         }
     }
     throw new Exception("Coupon with id '{$id}' does not exist in your Braintree account.");
 }
Exemplo n.º 3
0
 public function testAll_returnsAllDiscounts()
 {
     $newId = strval(rand());
     $discountParams = ["amount" => "100.00", "description" => "some description", "id" => $newId, "kind" => "discount", "name" => "php_discount", "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" => $discountParams]);
     $discounts = Braintree\Discount::all();
     foreach ($discounts as $discount) {
         if ($discount->id == $newId) {
             $actualDiscount = $discount;
         }
     }
     $this->assertNotNull($actualDiscount);
     $this->assertEquals($discountParams["amount"], $actualDiscount->amount);
     $this->assertEquals($discountParams["description"], $actualDiscount->description);
     $this->assertEquals($discountParams["id"], $actualDiscount->id);
     $this->assertEquals($discountParams["kind"], $actualDiscount->kind);
     $this->assertEquals($discountParams["name"], $actualDiscount->name);
     $this->assertFalse($actualDiscount->neverExpires);
     $this->assertEquals($discountParams["numberOfBillingCycles"], $actualDiscount->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;
 }
Exemplo n.º 5
0
 public function testToString()
 {
     $discountParams = array("amount" => "100.00", "description" => "some description", "id" => "1", "kind" => "discount", "name" => "php_discount", "neverExpires" => "false", "numberOfBillingCycles" => "1");
     $discount = Braintree\Discount::factory($discountParams);
     $this->assertEquals("Braintree\\Discount[amount=100.00, description=some description, id=1, kind=discount, name=php_discount, neverExpires=false, numberOfBillingCycles=1]", (string) $discount);
 }