Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/Payment/Mollie.php
<?php | <?php | ||||
namespace App\Providers\Payment; | namespace App\Providers\Payment; | ||||
use App\Payment; | use App\Payment; | ||||
use App\Utils; | use App\Utils; | ||||
use App\Wallet; | use App\Wallet; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Mollie\Api\Exceptions\ApiException; | |||||
class Mollie extends \App\Providers\PaymentProvider | class Mollie extends \App\Providers\PaymentProvider | ||||
{ | { | ||||
/** | /** | ||||
* Get a link to the customer in the provider's control panel | * Get a link to the customer in the provider's control panel | ||||
* | * | ||||
* @param \App\Wallet $wallet The wallet | * @param \App\Wallet $wallet The wallet | ||||
* | * | ||||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | class Mollie extends \App\Providers\PaymentProvider | ||||
*/ | */ | ||||
protected static function mollieMandate(Wallet $wallet) | protected static function mollieMandate(Wallet $wallet) | ||||
{ | { | ||||
$customer_id = $wallet->getSetting('mollie_id'); | $customer_id = $wallet->getSetting('mollie_id'); | ||||
$mandate_id = $wallet->getSetting('mollie_mandate_id'); | $mandate_id = $wallet->getSetting('mollie_mandate_id'); | ||||
// Get the manadate reference we already have | // Get the manadate reference we already have | ||||
if ($customer_id && $mandate_id) { | if ($customer_id && $mandate_id) { | ||||
$mandate = mollie()->mandates()->getForId($customer_id, $mandate_id); | try { | ||||
if ($mandate) {// && ($mandate->isValid() || $mandate->isPending())) { | return mollie()->mandates()->getForId($customer_id, $mandate_id); | ||||
return $mandate; | } catch (ApiException $e) { | ||||
} | // FIXME: What about 404? | ||||
if ($e->getCode() == 410) { | |||||
// The mandate is gone, remove the reference | |||||
$wallet->setSetting('mollie_mandate_id', null); | |||||
return null; | |||||
} | } | ||||
// Get all mandates from Mollie and find the active one | // TODO: Maybe we shouldn't always throw? It make sense in the job | ||||
/* | // but for example when we're just fetching wallet info... | ||||
foreach ($customer->mandates() as $mandate) { | throw $e; | ||||
if ($mandate->isValid() || $mandate->isPending()) { | |||||
$wallet->setSetting('mollie_mandate_id', $mandate->id); | |||||
return $mandate; | |||||
} | } | ||||
} | } | ||||
*/ | |||||
} | } | ||||
/** | /** | ||||
* Apply the successful payment's pecunia to the wallet | * Apply the successful payment's pecunia to the wallet | ||||
*/ | */ | ||||
protected static function creditPayment($payment, $mollie_payment) | protected static function creditPayment($payment, $mollie_payment) | ||||
{ | { | ||||
// Extract the payment method for transaction description | // Extract the payment method for transaction description | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |