Viewing file: StripePayment.php (2.87 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace Modules\PaymentGateway\SenderIdPurchaseGateway;
use App\Models\BillingRequest; use App\Models\Number; use Carbon\Carbon; use Illuminate\Support\Facades\Log;
class StripePayment 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 (!$credentials->stripe_pub_key || !$credentials->stripe_secret_key) { throw new \Exception('Credentials not found. Please contact with the administrator'); } return $credentials; }
public function senderId($sender_id) { $this->sender_id = $sender_id; return $this; } public function request($request) { $this->request = $request; 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() { try { $sender_id = $this->sender_id; $request = $this->request; $payment = $this->stripePayment($sender_id, $request); if (isset($payment->id)) { $sender_id = $this->sender_id; $sender_id->is_paid = 'yes'; $sender_id->save(); } $this->redirect_url = null; $this->return_view = null;
} catch (\Exception $ex) { Log::error($ex->getMessage()); $this->error_message= $ex->getMessage(); } }
/*Custom Function*/ function stripePayment($sender_id, $req) { $credentials = json_decode(get_settings('payment_gateway')); if (!$credentials->stripe_pub_key || !$credentials->stripe_secret_key) { throw new \Exception(trans('Invalid payment')); }
$stripe = new \Stripe\StripeClient($credentials->stripe_secret_key); $price = json_decode(get_settings('senderid_price'))->sender_id_price; return $stripe->charges->create([ 'amount' => $price * 100, 'currency' => "USD", 'source' => $req->stripeToken, 'description' => 'User:' . auth('customer')->user()->email . ' changed number to ' . $sender_id, ]); } }
|