Skip to content

Commit

Permalink
v3 groundwork
Browse files Browse the repository at this point in the history
  • Loading branch information
sandervanhooft committed Jan 6, 2025
1 parent 983ca0a commit 37f431b
Show file tree
Hide file tree
Showing 32 changed files with 1,311 additions and 106 deletions.
4 changes: 2 additions & 2 deletions database/migrations/create_applied_coupons_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAppliedCouponsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand All @@ -30,4 +30,4 @@ class CreateAppliedCouponsTable extends Migration
{
Schema::dropIfExists('applied_coupons');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_credits_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCreditsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -32,4 +32,4 @@ class CreateCreditsTable extends Migration
{
Schema::dropIfExists('credits');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_order_items_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrderItemsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -40,4 +40,4 @@ class CreateOrderItemsTable extends Migration
{
Schema::dropIfExists('order_items');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_orders_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrdersTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -43,4 +43,4 @@ class CreateOrdersTable extends Migration
{
Schema::dropIfExists('orders');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_payments_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePaymentsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -39,4 +39,4 @@ class CreatePaymentsTable extends Migration
{
Schema::dropIfExists('payments');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_redeemed_coupons_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRedeemedCouponsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -34,4 +34,4 @@ class CreateRedeemedCouponsTable extends Migration
{
Schema::dropIfExists('redeemed_coupons');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_refund_items_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRefundItemsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -38,4 +38,4 @@ class CreateRefundItemsTable extends Migration
{
Schema::dropIfExists('refund_items');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_refunds_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRefundsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -36,4 +36,4 @@ class CreateRefundsTable extends Migration
{
Schema::dropIfExists('refunds');
}
}
};
4 changes: 2 additions & 2 deletions database/migrations/create_subscriptions_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSubscriptionsTable extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -40,4 +40,4 @@ class CreateSubscriptionsTable extends Migration
{
Schema::dropIfExists('subscriptions');
}
}
};
80 changes: 0 additions & 80 deletions database/migrations/upgrade_to_cashier_v2.php.stub

This file was deleted.

28 changes: 28 additions & 0 deletions database/migrations/upgrade_to_cashier_v3.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
//
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
//
}
};
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2 align="center">Subscription billing with Laravel Cashier for Mollie
</h2>
<p align="center">
<img src="./.vuepress/public/assets/pages/laravelcashiermollie.jpg" title="Laravel Cashier Mollie">
<img src=".vuepress/public/assets/pages/laravelcashiermollie.jpg" title="Laravel Cashier Mollie">
</p>
<img src="https://private-user-images.githubusercontent.com/7265703/259759664-a6cf1db7-c252-43c1-a28d-845f3a0880ba.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyMTc2MjIsIm5iZiI6MTcxOTIxNzMyMiwicGF0aCI6Ii83MjY1NzAzLzI1OTc1OTY2NC1hNmNmMWRiNy1jMjUyLTQzYzEtYTI4ZC04NDVmM2EwODgwYmEuanBlZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDA4MjIwMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg4MmIwZDQyMjFkYzdlNjdhYTNkMmJlYTUyN2M4NTcwZTVhZWExYzUwY2JlNzcyNGQ1ODc3YTVhNzhmMTYzNGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.xeKYtt-tXd8RrS3CwOXauC433VeYJgF1E6FwbNvLkdc" title="Laravel Cashier Mollie Example"/>

Expand Down
5 changes: 2 additions & 3 deletions docs/.vuepress/config.js → docs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
},
{
'name': 'Sander van Hooft',
'email': 'info@sandervanhooft.com',
'homepage': 'https://www.sandervanhooft.com',
'email': 'sander@sandorian.com',
'homepage': 'https://www.sandorian.com',
'role': 'Developer'
}
],
Expand Down Expand Up @@ -52,7 +52,6 @@ module.exports = {
'/10-webhook',
'/11-testing',
'/12-faq',
//'/13-upgrade',
]
},
base: '/',
Expand Down
98 changes: 98 additions & 0 deletions docs/v2/01-installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Installation

First, make sure to add the Mollie key to your `.env` file. You can obtain an API key from the [Mollie dashboard](https://www.mollie.com/dashboard/developers/api-keys):

```dotenv
MOLLIE_KEY="test_xxxxxxxxxxx"
```

Now pull the package in using composer:

```bash
composer require mollie/laravel-cashier-mollie "^2.0"
```

## Setup

Once you have pulled in the package:

1. Run `php artisan cashier:install`.

2. Add these fields to your billable model's migration (typically the default "create_users_table" migration):

```php
$table->string('mollie_customer_id')->nullable();
$table->string('mollie_mandate_id')->nullable();
$table->decimal('tax_percentage', 6, 4)->default(0); // optional
$table->dateTime('trial_ends_at')->nullable(); // optional
$table->text('extra_billing_information')->nullable(); // optional
```

3. Run the migrations: `php artisan migrate`

4. Prepare the configuration files:

- configure at least one subscription plan in `config/cashier_plans.php`.

- in `config/cashier_coupons.php` you can manage your subscription coupons. By default an example coupon is enabled. Consider
disabling it before deploying to production.

- the base configuration is in `config/cashier.php`. Be careful while modifying this, in most cases you will not need
to.

5. Prepare the billable model (typically the default Laravel User model):

- Add the `Laravel\Cashier\Billable` trait.

- Optionally, override the method `mollieCustomerFields()` to configure what billable model fields are stored while creating the Mollie Customer.
Out of the box the `mollieCustomerFields()` method uses the default Laravel User model fields:

```php
public function mollieCustomerFields() {
return [
'email' => $this->email,
'name' => $this->name,
];
}
```
Learn more about storing data on the Mollie Customer [here](https://docs.mollie.com/reference/v2/customers-api/create-customer#parameters).

- Implement the `Laravel\Cashier\Order\Contracts\ProvidesInvoiceInformation` interface on your billable model. For example:

```php
/**
* Get the receiver information for the invoice.
* Typically includes the name and some sort of (E-mail/physical) address.
*
* @return array An array of strings
*/
public function getInvoiceInformation()
{
return [$this->name, $this->email];
}

/**
* Get additional information to be displayed on the invoice. Typically a note provided by the customer.
*
* @return string|null
*/
public function getExtraBillingInformation()
{
return null;
}
```

6. Schedule a periodic command to execute the `CashierRun` command. When processing lots of orders, consider increasing the job frequency to prevent hitting Mollie's rate limiter.

```php
use Illuminate\Support\Facades\Schedule;
use Laravel\Cashier\Console\Commands\CashierRun;

Schedule::command(CashierRun::class)
->hourly() // run as often as you like (daily, monthly, every minute, ...)
->withoutOverlapping(); // make sure to include this
```

You can find more about scheduling jobs using Laravel [here](https://laravel.com/docs/scheduling).

🎉 You're now good to go :).
Loading

0 comments on commit 37f431b

Please sign in to comment.