Exemplo n.º 1
0
 public function addToBillys($product)
 {
     $billys = new BillysBilling(env('BILLYS_KEY'));
     $result = $billys->makeBillyRequest('POST', '/products', ['product' => ['organizationId' => env('BILLY_ORGANIZATION'), 'name' => $product->product_name, 'productNo' => $product->id, 'prices' => [['unitPrice' => $product->product_price / 100, 'currencyId' => 'DKK']]]]);
     if ($result->status !== 200) {
         return response()->json(['message' => $result->body]);
     }
     // Save the billy id to the product model, so we can use it later
     $billyId = $product->billys_product_id = $result->body->products[0]->id;
     $product->push($billyId);
 }
Exemplo n.º 2
0
 /**
  * Handle the event.
  *
  * @param  OrderWasApproved  $event
  * @return void
  */
 public function handle(OrderWasApproved $event)
 {
     $billingId = $event->order['stripe_billing_id'];
     $amount = $event->order['amount'];
     Stripe::setApiKey(env('STRIPE_API_KEY'));
     $data = Charge::create(['amount' => $amount, 'currency' => 'dkk', 'customer' => $billingId, 'description' => 'Event charge']);
     Mail::send('emails.orderConfirmation', ['data' => $data], function ($message) {
         $message->to('*****@*****.**')->from('*****@*****.**')->subject('Welcome!');
     });
     // Send an SMS if the user has allowed it
     if ($event->order['sendSms'] == true) {
         Twilio::message('+4528559088', 'Your order was shipped!');
     }
     $billy = new BillysBilling(env('BILLY_KEY'));
     $date = Carbon::now()->format('Y-m-d');
     $billy->makeBillyRequest('POST', '/bankPayments', ['bankPayment' => ['organizationId' => env('BILLY_ORGANIZATION'), 'contactId' => $event->order['billys_contact_id'], 'entryDate' => $date, 'cashAmount' => $amount, 'cashSide' => 'debit', 'cashAccountId' => 'YYYHJlZ4Rceu0ApFuoVBWQ', 'associations' => [['subjectReference' => 'invoice:' . $event->order['billys_invoice_id']]]]]);
 }
Exemplo n.º 3
0
 public function sendToBilly()
 {
     $billy = new BillysBilling(env('BILLYS_KEY'));
     //Create a contact
     $res = $billy->request("GET", "/contacts");
     if ($res->status !== 200) {
         return response()->json(['message' => $res->body]);
     }
     $contactId = $res->body->contacts[0]->id;
     $res = $billy->request("GET", "/organization");
     if ($res->status !== 200) {
         echo "Something went wrong:\n\n";
         print_r($res->body);
         exit;
     }
     dd($organizationId = $res->body->organization->defaultInvoiceBankAccountId);
     //        $date = Carbon::now()->format('Y-m-d');
     //        defaultInvoiceBankAccount
     //        $request = $billy->makeBillyRequest('POST', '/invoices', [
     //            'invoice' => [
     //                'organizationId' => env('BILLY_ORGANIZATION'),
     //                'contactId' => $contactId,
     //                'entryDate' => $date,
     //                'paymentTermsDays' => 5,
     //                'state' => 'draft',
     //                'sentState' => 'unsent',
     //                'invoiceNo' => 1115,
     //                'currencyId' => 'DKK',
     //                'lines' => [
     //                    [
     //                        'productId' => '7hTuJ92QS3OagqmM9piJ3Q',
     //                        'unitPrice' => 500
     //                    ]
     //                ],
     //            ]
     //        ]);
     //
     //        if ($request->status !== 200) {
     //            return response()->json(['message' => $request->body]);
     //        }
     //
     //        $invoiceId = $request->body->invoices[0]->id;
     //
     //        $bankPayment = $billy->makeBillyRequest('POST', '/bankPayments', [
     //            'bankPayment' => [
     //                'organizationId' => env('BILLY_ORGANIZATION'),
     //                'contactId' => $contactId,
     //                'entryDate' => $date,
     //                'cashAmount' => 500,
     //                'cashSide' => 'debit',
     //                'cashAccountId' => 1,
     //                'associations' => [
     //                    [
     //                        'subjectReference' => 'invoice:' . $invoiceId,
     //                    ]
     //                ],
     //            ]
     //        ]);
     //
     //        if ($bankPayment->status !== 200) {
     //            return response()->json(['message' => $bankPayment->body]);
     //        }
 }
Exemplo n.º 4
-1
 /**
  * Handle the event.
  *
  * @param  OrderWasPlaced $event
  * @return void
  */
 public function handle(OrderWasPlaced $event)
 {
     $amount = $event->amount;
     $country = $event->order['country'];
     $vatRate = 25;
     $billing_id = $event->billing_id;
     $customerName = $event->order['first_name'] . ' ' . $event->order['last_name'];
     $customerAddress = $event->order['street'];
     $customerCity = $event->order['city'];
     $customerZip = $event->order['zip'];
     $customerEmail = $event->order['email'];
     $customerPhone = $event->order['phone'];
     $sendSms = $event->order['sendSms'];
     $checkUser = Auth::check() ? Auth::user()->id : 1;
     $products = Cart::content();
     // Specific for saving an invoice
     $date = Carbon::now()->format('Y-m-d');
     $lines = [];
     foreach ($products as $product) {
         $lines[] = ['productId' => $product->options->billys_product_id, 'unitPrice' => $product->price / 100];
     }
     $billy = new BillysBilling(env('BILLYS_KEY'));
     $billyContact = $billy->makeBillyRequest('POST', '/contacts', ['contact' => ['type' => 'person', 'organizationId' => env('BILLY_ORGANIZATION'), 'name' => $customerName, 'countryId' => $country, 'street' => $customerAddress, 'cityText' => $customerCity, 'zipcodeText' => $customerZip, 'phone' => $customerPhone, 'isCustomer' => true]]);
     $billyContactId = $billyContact->body->contacts[0]->id;
     $order = Order::create(['amount' => $amount, 'vat_rate' => $vatRate, 'stripe_billing_id' => $billing_id, 'customer_name' => $customerName, 'customer_address' => $customerAddress, 'customer_city' => $customerCity, 'customer_country' => $country, 'customer_zip' => $customerZip, 'customer_email' => $customerEmail, 'customer_phone_number' => $customerPhone, 'sendSms' => $sendSms, 'user_id' => $checkUser, 'billys_contact_id' => $billyContactId]);
     $billyInvoice = $billy->makeBillyRequest('POST', '/invoices', ['invoice' => ['organizationId' => env('BILLY_ORGANIZATION'), 'contactId' => $billyContactId, 'entryDate' => $date, 'paymentTermsDays' => 5, 'state' => 'approved', 'sentState' => 'unsent', 'invoiceNo' => $order->id, 'currencyId' => 'DKK', 'lines' => $lines]]);
     $order->billys_invoice_id = $billyInvoice->body->invoices[0]->id;
     $order->save();
 }