Viewing file: MolliePayment.php (3.89 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\SenderIdPurchaseGateway;
use App\Models\BillingRequest; use App\Models\Customer; use App\Models\Number; use App\Models\NumberRequest; use App\Models\SenderId; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log;
class MolliePayment implements PaymentInterface { public $numberReq; public $redirect_url; public $error_message; public $return_view; public $will_redirect= false;
public function __construct() {
}
public function pay() { // TODO: Implement pay() method. }
public function getCredentials() { $credentials = json_decode(get_settings('payment_gateway'));
if (!isset($credentials->mollie_status) || !$credentials->mollie_api_key || $credentials->mollie_status != 'active') { throw new \Exception('Credentials not found. Please contact with the administrator'); } return $credentials; }
public function senderID($senderID) { $this->sender_id = $senderID; return $this; }
public function will_redirect() { // TODO: Implement will_redirect() method. return $this->will_redirect; }
public function redirect_url() { // TODO: Implement redirect_url() method. return $this->redirect_url; } public function return_view() { // TODO: Implement redirect_url() method. return $this->return_view; } public function error_message() { // TODO: Implement error_message() method. return $this->error_message; }
public function process() { $mollieData = $this->molliePayment($this->numberReq); if ($mollieData && $mollieData->id) { $this->redirect_url = $mollieData->getCheckoutUrl(); $this->will_redirect = true; $this->return_view = null; } }
function molliePayment($senderID) {
$credentials = $this->getCredentials();
if (!isset($credentials->mollie_status) || !$credentials->mollie_api_key || $credentials->mollie_status != 'active') { throw new \Exception(trans('Invalid Payment')); } $price = json_decode(get_settings('senderid_price'))->sender_id_price; $mollie = new \Mollie\Api\MollieApiClient(); $mollie->setApiKey($credentials->mollie_api_key); $payment = $mollie->payments->create([ "amount" => [ "currency" => 'USD', "value" => $price . "" ], "description" => "For number upgrade #" . $senderID->id, "redirectUrl" => route('paymentgateway::payment.number.mollie.success'), "webhookUrl" => route('paymentgateway::payment.number.changenumber.mollie.webhook', ['id' => $senderID->id]), ]);
return $payment; }
public function processMollieSuccess() { return redirect()->route('customer.numbers.purchase')->with('success', trans('Congratulations! Your number successfully purchase')); }
public function processMollieWebhook($sender_id, Request $request) { if (!$sender_id) { Log::info("user sender-id not found"); exit; };
$senderId = SenderId::find($sender_id);
if (!$senderId) { Log::info("Sender-id Request not found -" . $sender_id); exit; };
$senderId->is_paid = 'yes'; $senderId->save();
$credentials = json_decode(get_settings('payment_gateway'));
if (!isset($credentials->mollie_status) || !$credentials->mollie_api_key || $credentials->mollie_status != 'active') { Log::info(trans('Invalid Payment')); exit(); }
$mollie = new \Mollie\Api\MollieApiClient(); $mollie->setApiKey($credentials->mollie_api_key); $payment = $mollie->payments->get($request->id);
}
}
|