public function testCouponCanBeRetrieved() { $invoice = new Invoice(m::mock('Laravel\\Cashier\\Contracts\\Billable'), (object) ['discount' => (object) ['coupon' => (object) ['id' => 'coupon-code']]]); $this->assertEquals('coupon-code', $invoice->coupon()); }
/** * Create a local invoice for the given billable entity. * * @param mixed $billable * @param \Laravel\Cashier\Invoice $invoice * @return \Laravel\Spark\LocalInvoice */ protected function createForBillable($billable, $invoice) { if ($existing = $billable->localInvoices()->where('provider_id', $invoice->id)->first()) { return $existing; } return $billable->localInvoices()->create(['provider_id' => $invoice->id, 'total' => $invoice->rawTotal() - $invoice->rawTotal() * $billable->taxPercentage(), 'tax' => $invoice->rawTotal() * $billable->taxPercentage(), 'card_country' => null, 'billing_state' => null, 'billing_zip' => null, 'billing_country' => null]); }
/** * Create a local invoice for the given billable entity. * * @param mixed $billable * @param \Laravel\Cashier\Invoice $invoice * @return \Laravel\Spark\LocalInvoice */ protected function createForBillable($billable, $invoice) { if ($existing = $billable->localInvoices()->where('provider_id', $invoice->id)->first()) { return $existing; } return $billable->localInvoices()->create(['provider_id' => $invoice->id, 'total' => $invoice->rawTotal() / 100, 'tax' => $invoice->asStripeInvoice()->tax / 100, 'card_country' => $billable->card_country, 'billing_state' => $billable->billing_state, 'billing_zip' => $billable->billing_zip, 'billing_country' => $billable->billing_country, 'vat_id' => $billable->vat_id]); }
/** * Notify the given user about a new invoice. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param \Laravel\Cashier\Invoice $invoice * @return void */ public function notify(Authenticatable $user, Invoice $invoice) { $invoiceData = array_merge(['vendor' => 'Vendor', 'product' => 'Product', 'vat' => new ViewExpression(nl2br(e($user->extra_billing_info)))], Spark::generateInvoicesWith()); $data = compact('user', 'invoice', 'invoiceData'); Mail::send('spark::emails.billing.invoice', $data, function ($message) use($user, $invoice, $invoiceData) { $message->to($user->email, $user->name)->subject('Your ' . $invoiceData['product'] . ' Invoice')->attachData($invoice->pdf($invoiceData), 'invoice.pdf'); }); }