예제 #1
0
파일: OfferTest.php 프로젝트: bitller/nova
 /**
  * Test creation of new offer.
  */
 public function test_it_create_new_offer()
 {
     // Generate new offer
     $generatedOffer = factory(App\Offer::class)->make();
     // Insert in database
     $offer = Offer::create(['paymill_offer_id' => $generatedOffer->paymill_offer_id, 'name' => $generatedOffer->name, 'amount' => $generatedOffer->amount, 'currency' => $generatedOffer->currency, 'interval' => $generatedOffer->interval]);
     // Check if offer exists in database
     $this->seeInDatabase('offers', ['paymill_offer_id' => $offer->paymill_offer_id, 'name' => $offer->name, 'amount' => $offer->amount, 'interval' => $offer->interval, 'currency' => $offer->currency]);
 }
예제 #2
0
 /**
  * Store a newly created Cruiseline.
  *
  * @param Request $request
  * @param Cruiseline $brand
  * @return mixed
  */
 public function store(CreateOffer $request)
 {
     $offer = Offer::create($request->all());
     if ($request->hasFile('image')) {
         if ($request->file('image')->isValid()) {
             $image = $request->file('image');
             $moveImage = $image->move(public_path() . '/uploads', $filename = time() . '-' . $image->getClientOriginalName());
             $offer->file = $filename;
         } else {
             return redirect()->back()->withInput();
         }
     }
     $offer->save();
     return redirect('home/offers');
 }
예제 #3
0
 /**
  * Allow admin to create new offers.
  *
  * @param CreateNewOfferRequest $request
  */
 public function create(CreateNewOfferRequest $request)
 {
     // Create new paymill request
     $paymillRequest = new \Paymill\Request(env('PAYMILL_API_KEY'));
     $currency = 'EUR';
     $interval = '1 MONTH';
     // Create new offer
     $paymillOffer = new \Paymill\Models\Request\Offer();
     $paymillOffer->setAmount($request->get('offer_amount'))->setCurrency($currency)->setInterval($interval)->setName($request->get('offer_name'));
     $response = $paymillRequest->create($paymillOffer);
     $promoCode = $request->get('promo_code');
     $enableOffer = $request->get('enable_offer');
     $useOnSignUp = $request->get('use_on_sign_up');
     // If this offer will be used on sign up make sure it is the only one
     if ($useOnSignUp) {
         Offer::where('use_on_sign_up', true)->update(['use_on_sign_up' => false]);
         $promoCode = '';
         $enableOffer = false;
     }
     // An enabled offer can not be used on sign up
     if ($enableOffer) {
         $useOnSignUp = false;
     }
     // Save in database
     Offer::create(['paymill_offer_id' => $response->getId(), 'name' => $request->get('offer_name'), 'amount' => $request->get('offer_amount'), 'interval' => $interval, 'currency' => $currency, 'promo_code' => $promoCode, 'use_on_sign_up' => (bool) $useOnSignUp, 'disabled' => !(bool) $enableOffer]);
     // Return response
     $ajaxResponse = new AjaxResponse();
     $ajaxResponse->setSuccessMessage(trans('offers.offer_created'));
     return response($ajaxResponse->get())->header('Content-Type', 'application/json');
 }