Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GoUrl.io Crypto Payment Gateway for Laravel

License

NotificationsYou must be signed in to change notification settings

Kalachor1/laravel-crypto-payment-gateway

 
 

Repository files navigation

GoUrl.io Crypto Payment Gateway for Laravel.

Latest Version on PackagistTotal DownloadsGitHub Actions

preview

Table of Contents


Installation

You can install the package via composer:

composer require victorybiz/laravel-crypto-payment-gateway

Next, you should publish the configuration, migration and asset files using thevendor:publish Artisan command. The configuration, migration and asset files will be placed in your application'sconfig,database/migrations andpublic/vendor directory respectively:

php artisan vendor:publish --provider="Victorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGatewayServiceProvider"

Requirements

This package is create a laravel wrapper on theGoUrl.io'sCryptoAPI Payment Gatway.

  • Register for Free or Login on theGoUrl.io website.
  • Createnew payment box.
  • Ensure to specify your External wallet address and Callback Url
  • Obtain the Public Key and Private of each coin's payment box you want to support.

Dependencies

Thecompact andstandard box template usesAlpinejs andTailwindCSS. While thegourl-cryptobox-iframe andgourl-cryptobox-boostrap uses assets provided byGoUrl.io. You do not need to install any of the dependencies, the package uses the CDN version of dependencies.

Configuration

You need create the following files;

  • APaymentController with acallback method.Learn more below.
  • A static class method anywhere in your application to hookIPN (Instant Payment Notification). Preferably you can just define the static methodpublic static function ipn($cryptoPaymentModel, $payment_details, $box_status){..} in the samePaymentController for easy code management.Learn more below
  • Define the payment routes.
  • Define the public key and private keys in environment file
Define payment routes
// routes/web.php// You can protect the 'payments.crypto.pay' route with `auth` middleware to allow access by only authenticated userRoute::match(['get','post'],'/payments/crypto/pay',Victorybiz\LaravelCryptoPaymentGateway\Http\Controllers\CryptoPaymentController::class)                ->name('payments.crypto.pay');// You you need to create your own callback controller and define the route below// The callback route should be a publicly accessible route with no auth// However, you may also exclude the route from CSRF Protection by adding their URIs to the $except property of the VerifyCsrfToken middleware.Route::post('/payments/crypto/callback', [App\Http\Controllers\Payment\PaymentController::class,'callback'])                ->withoutMiddleware(['web','auth']);

Learn more aboutThe Callback Route below.

Define the public key and private keys in environment file

Defined the created payment box's public key and private key for the various coins in your.env file.

GOURL_PAYMENTBOX_BITCOIN_PUBLIC_KEYGOURL_PAYMENTBOX_BITCOIN_PRIVATE_KEYGOURL_PAYMENTBOX_BITCOINCASH_PUBLIC_KEYGOURL_PAYMENTBOX_BITCOINCASH_PRIVATE_KEY

Config Options

See the publishedconfig/laravel-crypto-payment-gateway.php for available options to customize the payment box like changinglogo,box_template,box_template_options and other configuration options.

Usage

Payment Data Submission

The payment data can be submitted in the following ways;

  • Form Submit
  • AJAX Request
  • Session Redirect (through controller, Livewire component or anywhere in your application)

Which ever method data fieldamount in BTC oramountUSD need to be sent, both cannot be used. And optional data fieldsuserID,orderID (if you want to reference the data to any model in app e.g Product model) andredirect (a url you want to redirect to once payment is received).

Usage with Form Submit
<formid="payment-form"method="post"action="{{ route('payments.crypto.pay) }}">  @csrf<inputtype="text"name="amountUSD"placeholder="Amount"><inputtype="hidden"name="userID"value="{{ Auth::user()->id }}"><inputtype="hidden"name="orderID"value="1"><inputtype="hidden"name="redirect"value="{{ url()->full() }}"><buttontype="submit">Pay</button></form>
Usage with AJAX Request
axios({method:"post",url:"/payments/crypto/pay",data:{amountUSD:20.50,userID:1,orderID:101,redirect:'https://domain.com/redirect-url',},headers:{'Accept':'application/json'// Ensure you include your TOKEN as well},}).then(function(response){// The url is available in `data` key of the json response:// {//   status: true,//   message: 'Request successful.',//   data: 'https://your-domain.com/payments/crypto/pay?cryptopsid=some-unique-token-string'// }if(response.data.status===true){constpaymentUrl=response.data.datawindow.location=paymentUrl}}).catch(function(response){//handle errorconsole.log(response);});
Usage with Session Redirect (through controller, Livewire component or anywhere in your application)

You need to ensure you validate your data before sending to the payment gateway

// This could be in a controller method or livewire component methoduseVictorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGateway;$payment_url = LaravelCryptoPaymentGateway::startPaymentSession(['amountUSD' =>$validatedData['amount'],// OR 'amount' when sending BTC value'orderID' =>$product->id,'userID' => Auth::user()->id,'redirect' =>url()->full(),]);// redirect to the payment pageredirect()->to($payment_url);

The Callback

When a user has made a payment, theGoUrl.io's server will send payment data using HTTP POST method on your callback url specified in field Callback URL of your crypto payment box.

Callback Controller

Create aPaymentController and call instance of Laravel Crypto Payment Gateway's callback method.

<?phpnamespaceApp\Http\Controllers\Payment;useApp\Http\Controllers\Controller;useIlluminate\Http\Request;useIlluminate\Support\Facades\Auth;useVictorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGateway;class PaymentControllerextends Controller{/**     * Cryptobox callback.     */publicfunctioncallback(Request$request)    {return LaravelCryptoPaymentGateway::callback();    }}
Callback Route

Define the callback route to the created controller, the callback route should be a publicly accessible route with no auth. However, you may also exclude the route from CSRF Protection by adding their URIs to the$except property of theVerifyCsrfToken middleware.If you use Cloudflare & Mod_Security & other CDN services,Click Here to view theGoUrl.io's server IPs you need to add in Whitelist.

// routes/web.php Route::post('/payments/crypto/callback', [App\Http\Controllers\Payment\PaymentController::class,'callback'])                ->withoutMiddleware(['web','auth']);

IPN (Instant Payment Notification)

Once theGoUrl.io'sCryptobox Class finished processing the received callback behind the scene, then it make a call to acryptobox_new_payment(...) function which allows you to define your processing after payment. To hook on to this function to handle IPN (Instant payment notification) with your custom processing like sending email notifications and giving value to the user once payment is confirmed, create a static class method.This can be a static class method defined anywhere in your application.Preferably you can just define the static method in the samePaymentController for easy code management.

<?phpnamespaceApp\Http\Controllers\Payment;useApp\Http\Controllers\Controller;useIlluminate\Http\Request;useIlluminate\Support\Facades\Auth;useVictorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGateway;class PaymentControllerextends Controller{//.../**     * Cryptobox IPN Example     *     * @param \Victorybiz\LaravelCryptoPaymentGateway\Models\CryptoPaymentModel $cryptoPaymentModel     * @param array $payment_details     * @param string $box_status     * @return bool     */publicstaticfunctionipn($cryptoPaymentModel,$payment_details,$box_status)    {if ($cryptoPaymentModel) {/*            // ADD YOUR CODE HERE            // ------------------            // For example, you have a model `UserOrder`, you can create new Bitcoin payment record to this model            $userOrder = UserOrder::where('payment_id', $cryptoPaymentModel->paymentID)->first();            if (!$userOrder)            {                UserOrder::create([                    'payment_id' => $cryptoPaymentModel->paymentID,                    'user_id'    => $payment_details["user"],                    'order_id'   => $payment_details["order"],                    'amount'     => floatval($payment_details["amount"]),                    'amountusd'  => floatval($payment_details["amountusd"]),                    'coinlabel'  => $payment_details["coinlabel"],                    'txconfirmed'  => $payment_details["confirmed"],                    'status'     => $payment_details["status"],                ]);            }            // ------------------            // Received second IPN notification (optional) - Bitcoin payment confirmed (6+ transaction confirmations)            if ($userOrder && $box_status == "cryptobox_updated")            {                $userOrder->txconfirmed = $payment_details["confirmed"];                $userOrder->save();            }            // ------------------            */// Onetime action when payment confirmed (6+ transaction confirmations)if (!$cryptoPaymentModel->processed &&$payment_details["confirmed"])            {// Add your custom logic here to give value to the user.// ------------------// set the status of the payment to processed// $cryptoPaymentModel->setStatusAsProcessed();// ------------------// Add logic to send notification of confirmed/processed payment to the user if any            }                    }returntrue;    }}

Then update the publishedconfig/laravel-crypto-payment-gateway.php and set value forhook_ipn key to hook IPN (Instant Payment Notification) function to the static class method defined above.config file

// config/laravel-crypto-payment-gateway.php/** * Hook IPN (Instant payment notification) to the following static class method. * In this static class method, you can  add your custom logic and give value to the user once your confirmed payment box status. * You can also add payment notification logic. * This can be a static class method defined anywhere in your application. * This can also be static method/action defined in controller class but route must not be defined for the action. * * The Static Method Definition in your class: * @param \Victorybiz\LaravelCryptoPaymentGateway\Models\CryptoPaymentModel $cryptoPaymentModel * @param array $payment_details * @param string $box_status * @return bool * public static function ipn($cryptoPaymentModel, $payment_details, $box_status) * { *  // Add your custom logic here. *  return true; * } * * Example: [\Victorybiz\LaravelCryptoPaymentGateway\Http\Controllers\CryptoPaymentController::class, 'ipn'] */'hook_ipn' => [\App\Http\Controllers\Payment\PaymentController,'ipn'],

Eloquent Model forcrypto_payments table

This package provide eloquent model for thecrypto_payments.

useVictorybiz\LaravelCryptoPaymentGateway\Models\CryptoPaymentModel;$cryptoPayment = CryptoPaymentModel::find($paymentID);$cryptoPayment = CryptoPaymentModel::where('paymentID',$paymentID);$processedCryptoPayment = CryptoPaymentModel::where('processed',true);

Advanced Usage

Instance of GoUrl.io PHP Class API (cryptobox.class.php)

This package provide access to instance of the coreGoUrl.io'scryptobox.class.php which this package uses under the hood.

useVictorybiz\LaravelCryptoPaymentGateway\LaravelCryptoPaymentGateway;$laravelCryptoPaymentGateway =newLaravelCryptoPaymentGateway;$cryptobox =$laravelCryptoPaymentGateway->getCryptobox($options = []);$payment_history =$cryptobox->payment_history($boxID ="",$orderID ="",$userID ="",$countryID ="",$boxType ="",$period ="7 DAY");

Click Here to learn more about GoUrl.io PHP Class API and the available methods.

Resources

The following packages was put together to makeup this seamless package.

Testing

composertest

Changelog

Please seeCHANGELOG for more information what has changed recently.

Contributing

Please seeCONTRIBUTING for details.

Security

If you discover any security related issues, please emaillavictorybiz@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please seeLicense File for more information.

Laravel Package Boilerplate

This package was generated using theLaravel Package Boilerplate.

About

GoUrl.io Crypto Payment Gateway for Laravel

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS85.5%
  • PHP12.6%
  • Blade1.1%
  • Other0.8%

[8]ページ先頭

©2009-2025 Movatter.jp