Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Payment method as array #210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/FirstPayment/FirstPaymentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions src/FirstPayment/Traits/PaymentMethodString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Cashier\FirstPayment\Traits;

trait PaymentMethodString
{
/**
* Backwards compatible: split strings into array
*
* @param string $method
*
* @return string[]
*/
private function castPaymentMethodString(string $method)
{
return collect(explode(',', $method))
->map(function ($methodString) {
return trim($methodString);
})
->filter()
->unique();
}
}
4 changes: 2 additions & 2 deletions src/Plan/Contracts/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions src/Plan/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -49,8 +53,8 @@ class Plan implements PlanContract
/**
* The first payment method
*
* @var string
* @example ideal
* @var array
* @example ['ideal']
*/
protected $firstPaymentMethod;

Expand Down Expand Up @@ -146,19 +150,23 @@ public function setDescription(string $description)
}

/**
* @return string
* @return array
*/
public function firstPaymentMethod()
{
return $this->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;
Expand Down