Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/Payment/Mollie.php
Show All 31 Lines | public function customerLink(Wallet $wallet): ?string | ||||
); | ); | ||||
} | } | ||||
/** | /** | ||||
* Create a new auto-payment mandate for a wallet. | * Create a new auto-payment mandate for a wallet. | ||||
* | * | ||||
* @param \App\Wallet $wallet The wallet | * @param \App\Wallet $wallet The wallet | ||||
* @param array $payment Payment data: | * @param array $payment Payment data: | ||||
* - amount: Value in cents | * - amount: Value in cents (optional) | ||||
* - currency: The operation currency | * - currency: The operation currency | ||||
* - description: Operation desc. | * - description: Operation desc. | ||||
* | * | ||||
* @return array Provider payment data: | * @return array Provider payment data: | ||||
* - id: Operation identifier | * - id: Operation identifier | ||||
* - redirectUrl: the location to redirect to | * - redirectUrl: the location to redirect to | ||||
*/ | */ | ||||
public function createMandate(Wallet $wallet, array $payment): ?array | public function createMandate(Wallet $wallet, array $payment): ?array | ||||
{ | { | ||||
// Register the user in Mollie, if not yet done | // Register the user in Mollie, if not yet done | ||||
$customer_id = self::mollieCustomerId($wallet, true); | $customer_id = self::mollieCustomerId($wallet, true); | ||||
if (!isset($payment['amount'])) { | |||||
$payment['amount'] = 0; | |||||
} | |||||
$request = [ | $request = [ | ||||
'amount' => [ | 'amount' => [ | ||||
'currency' => $payment['currency'], | 'currency' => $payment['currency'], | ||||
'value' => '0.00', | 'value' => sprintf('%.2f', $payment['amount'] / 100), | ||||
], | ], | ||||
'customerId' => $customer_id, | 'customerId' => $customer_id, | ||||
'sequenceType' => 'first', | 'sequenceType' => 'first', | ||||
'description' => $payment['description'], | 'description' => $payment['description'], | ||||
'webhookUrl' => Utils::serviceUrl('/api/webhooks/payment/mollie'), | 'webhookUrl' => Utils::serviceUrl('/api/webhooks/payment/mollie'), | ||||
'redirectUrl' => Utils::serviceUrl('/wallet'), | 'redirectUrl' => Utils::serviceUrl('/wallet'), | ||||
'locale' => 'en_US', | 'locale' => 'en_US', | ||||
// 'method' => 'creditcard', | // 'method' => 'creditcard', | ||||
]; | ]; | ||||
// Create the payment in Mollie | // Create the payment in Mollie | ||||
$response = mollie()->payments()->create($request); | $response = mollie()->payments()->create($request); | ||||
if ($response->mandateId) { | if ($response->mandateId) { | ||||
$wallet->setSetting('mollie_mandate_id', $response->mandateId); | $wallet->setSetting('mollie_mandate_id', $response->mandateId); | ||||
} | } | ||||
// Store the payment reference in database | |||||
$payment['status'] = $response->status; | |||||
$payment['id'] = $response->id; | |||||
$payment['type'] = self::TYPE_MANDATE; | |||||
$this->storePayment($payment, $wallet->id); | |||||
return [ | return [ | ||||
'id' => $response->id, | 'id' => $response->id, | ||||
'redirectUrl' => $response->getCheckoutUrl(), | 'redirectUrl' => $response->getCheckoutUrl(), | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Revoke the auto-payment mandate for the wallet. | * Revoke the auto-payment mandate for the wallet. | ||||
▲ Show 20 Lines • Show All 408 Lines • Show Last 20 Lines |