Example #1
0
 /**
  * @param $token
  * @param $total
  * @param Collection $receiptItems
  * @param User       $user
  *
  * @return bool
  */
 public function pay($token, $total, Collection $receiptItems, User $user = null)
 {
     DB::beginTransaction();
     $receiptDetails = ['total' => $total];
     if ($user != null) {
         $receiptDetails['user_id'] = $user->id;
         $receiptDetails['address_id'] = $user->primary_address_id;
     }
     $receipt = Receipt::create($receiptDetails);
     $receipt->items()->saveMany($receiptItems);
     $chargeData = ['currency' => 'USD', 'amount' => $total, 'token' => $token, 'order' => $receipt->id, 'description' => view('store.php-receipt', ['receiptItems' => $receipt->items]), 'metadata' => ['receiptId' => $receipt->id]];
     // allow Stripe to send receipt emails for us
     if ($user != null) {
         $chargeData['receipt_email'] = $user->email;
     }
     /** @var \Omnipay\Stripe\Message\Response $response */
     $response = Omnipay::purchase($chargeData)->send();
     if ($response->isSuccessful()) {
         $receipt->update(['payment_reference_number' => $response->getTransactionReference()]);
         $this->receipt = $receipt;
         DB::commit();
         return true;
     }
     throw new PaymentFailed($response->getMessage());
 }
 private function seedReceipts()
 {
     $teen = Program::findOrFail(Program::TEEN);
     $receipt = Receipt::create(['total' => $teen->registration_fee * 3, 'payment_reference_number' => uniqid(), 'user_id' => DatabaseSeeder::$guardian->id, 'address_id' => DatabaseSeeder::$guardian->primary_address_id]);
     $receipt->items()->create(['sku' => $teen->sku, 'description' => $teen->name . ' Seasonal Registration', 'quantity' => '3', 'price' => $teen->registration_fee]);
     $createdAt = Carbon::now()->subMonth();
     $beginner = Program::findOrFail(Program::BEGINNER);
     $receipt = Receipt::create(['total' => $beginner->registration_fee * 3, 'payment_reference_number' => uniqid(), 'user_id' => DatabaseSeeder::$guardian->id, 'address_id' => DatabaseSeeder::$guardian->primary_address_id, 'created_at' => $createdAt]);
     $receipt->items()->create(['sku' => $beginner->sku, 'description' => $beginner->name . ' Seasonal Registration', 'quantity' => '3', 'price' => $beginner->registration_fee, 'created_at' => $createdAt]);
 }
Example #3
0
 private function seedReceipt(User $user) : Receipt
 {
     $program = Program::firstOrFail();
     $receipt = Receipt::create(['total' => 15.0, 'payment_reference_number' => uniqid(), 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'user_id' => $user->id, 'address_id' => $user->primary_address_id]);
     $receipt->items()->create(['sku' => $program->sku, 'description' => $program->name . ' Seasonal Registration', 'quantity' => '2', 'price' => $program->registration_fee]);
     return $receipt;
 }