diff --git a/config/cashier.php b/config/cashier.php index a132ada3..be42f613 100644 --- a/config/cashier.php +++ b/config/cashier.php @@ -46,11 +46,11 @@ 'webhook_url' => 'webhooks/mollie/first-payment', /** - * A comma-separated list of allowed Mollie payment methods for the first payment. Make sure the methods are - * enabled in the Mollie dashboard. Set to NULL to let Mollie handle this for you. Can be overridden per plan. - * @example 'ideal,creditcard' + * Array of allowed Mollie payment methods for the first payment. Make sure the methods are + * enabled in the Mollie dashboard. Set to [] to let Mollie handle this for you. Can be overridden per plan. + * @example ['ideal', 'creditcard'] */ - 'method' => null, + 'method' => [], /** * The default url the customer is redirected to after the Mollie first payment checkout screen. Can be diff --git a/src/FirstPayment/FirstPaymentBuilder.php b/src/FirstPayment/FirstPaymentBuilder.php index 90b79faf..04b8e046 100644 --- a/src/FirstPayment/FirstPaymentBuilder.php +++ b/src/FirstPayment/FirstPaymentBuilder.php @@ -6,10 +6,13 @@ use Illuminate\Support\Str; use Laravel\Cashier\Cashier; use Laravel\Cashier\FirstPayment\Actions\ActionCollection; +use Laravel\Cashier\FirstPayment\Traits\PaymentMethodString; use Mollie\Api\Types\SequenceType; class FirstPaymentBuilder { + use PaymentMethodString; + /** * The billable model. * @@ -136,11 +139,15 @@ public function create() } /** - * @param string $method + * @param array|string $method * @return FirstPaymentBuilder */ - public function setFirstPaymentMethod(?string $method) + public function setFirstPaymentMethod($method) { + if(is_string($method)) { + $method = $this->castPaymentMethodString($method); + } + $this->method = $method; return $this; diff --git a/src/FirstPayment/Traits/PaymentMethodString.php b/src/FirstPayment/Traits/PaymentMethodString.php new file mode 100644 index 00000000..6389cd7f --- /dev/null +++ b/src/FirstPayment/Traits/PaymentMethodString.php @@ -0,0 +1,23 @@ +map(function ($methodString) { + return trim($methodString); + }) + ->filter() + ->unique(); + } +} diff --git a/src/Plan/Contracts/Plan.php b/src/Plan/Contracts/Plan.php index 4083ce21..343fa556 100644 --- a/src/Plan/Contracts/Plan.php +++ b/src/Plan/Contracts/Plan.php @@ -54,10 +54,10 @@ public function setFirstPaymentAmount(Money $firstPaymentAmount); public function firstPaymentMethod(); /** - * @param string $firstPaymentMethod + * @param array|string $firstPaymentMethod * @return Plan */ - public function setFirstPaymentMethod(?string $firstPaymentMethod); + public function setFirstPaymentMethod($firstPaymentMethod); /** * The description for the mandate payment order item. diff --git a/src/Plan/Plan.php b/src/Plan/Plan.php index 024c1391..05b6cc5e 100644 --- a/src/Plan/Plan.php +++ b/src/Plan/Plan.php @@ -4,12 +4,16 @@ namespace Laravel\Cashier\Plan; +use Laravel\Cashier\FirstPayment\Traits\PaymentMethodString; use Laravel\Cashier\Order\OrderItemPreprocessorCollection; use Laravel\Cashier\Plan\Contracts\Plan as PlanContract; use Money\Money; class Plan implements PlanContract { + + use PaymentMethodString; + /** * A unique reference for this plan. * @@ -49,8 +53,8 @@ class Plan implements PlanContract /** * The first payment method * - * @var string - * @example ideal + * @var array + * @example ['ideal'] */ protected $firstPaymentMethod; @@ -146,7 +150,7 @@ public function setDescription(string $description) } /** - * @return string + * @return array */ public function firstPaymentMethod() { @@ -154,11 +158,15 @@ public function firstPaymentMethod() } /** - * @param string $firstPaymentMethod + * @param array|string $firstPaymentMethod * @return $this */ - public function setFirstPaymentMethod(?string $firstPaymentMethod) + public function setFirstPaymentMethod($firstPaymentMethod) { + if (is_string($firstPaymentMethod)) { + $firstPaymentMethod = $this->castPaymentMethodString($firstPaymentMethod); + } + $this->firstPaymentMethod = $firstPaymentMethod; return $this;