PHPackages                             kristof202/cryptomus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kristof202/cryptomus

ActiveProject[API Development](/categories/api)

kristof202/cryptomus
====================

Laravel wrapper for the Cryptomus API

v1.0(2y ago)030MITPHPPHP ^7.3|^8.0

Since Mar 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kristof202/cryptomus)[ Packagist](https://packagist.org/packages/kristof202/cryptomus)[ RSS](/packages/kristof202-cryptomus/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Laravel wrapper for the Cryptomus API.
======================================

[](#laravel-wrapper-for-the-cryptomus-api)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require kristof202/cryptomus
```

The service provider will automatically register itself.

You must publish the config file with:

```
php artisan vendor:publish --provider="Kristof\Cryptomus\CryptomusServiceProvider" --tag="config"
```

This is the contents of the config file that will be published at `config/cryptomus.php`:

```
return [
    'MerchantID' => env('CRYPTOMUS_MERCHANT_ID'),
    'PaymentKey' => env('CRYPTOMUS_PAYMENT_KEY'),
    'webhookJobs' => [
        // 'cancel' => \App\Jobs\CryptomusWebhook\HandleCancel::class,
        // 'paid' => \App\Jobs\CryptomusWebhook\HandlePaid::class,
        // 'wrong_amount' => \App\Jobs\CryptomusWebhook\HandleWrongAmount::class,
        // 'paid_over' => \App\Jobs\CryptomusWebhook\HandlePaidOver::class,
    ],
    'webhookModel' => Kristof\Cryptomus\Models\CryptomusWebhookCall::class,
];
```

In the `PaymentKey` key of the config file you should add a valid payment key. You can find the keys at \[the Cryptomus Merchants dashboard\].

Next, you must publish the migration with:

```
php artisan vendor:publish --provider="Kristof\Cryptomus\CryptomusServiceProvider" --tag="migrations"
```

After the migration has been published you can create the `cryptomus_webhook_calls` table by running the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Creating an invoice

[](#creating-an-invoice)

```
$payment = Cryptomus::createPayment([
            "amount"=> "15",
	        "currency"=> "USD",
            "order_id"=>"1",
        ]);
```

### Webhooks

[](#webhooks)

Cryptomus will send out webhooks for several event types. check the Cryptomus API documentation.

Cryptomus will sign all requests hitting the webhook url of your app. This package will automatically verify if the signature is valid. If it is not, the request was probably not sent by Cryptomus.

Unless something goes terribly wrong, this package will always respond with a `200` to webhook requests. All webhook requests with a valid signature will be logged in the `cryptomus_webhook_calls` table. The table has a `payload` column where the entire payload of the incoming webhook is saved.

If the signature is not valid, the request will not be logged in the `cryptomus_webhook_calls` table but a `Kristof\Cryptomus\Exceptions\WebhookFailed` exception will be thrown. If something goes wrong during the webhook request the thrown exception will be saved in the `exception` column. In that case the controller will send a `500` instead of `200`.

There are two ways this package enables you to handle webhook requests: you can opt to queue a job or listen to the events the package will fire.

### Handling webhook requests using jobs

[](#handling-webhook-requests-using-jobs)

If you want to do something when a specific event type comes in you can define a job that does the work. Here's an example of such a job:

```
