RevolutMerchantServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 2
nc 1
nop 0
1
<?php
2
3
namespace tbclla\RevolutMerchant\Providers;
4
5
use Illuminate\Support\Facades\Blade;
6
use Illuminate\Support\ServiceProvider;
7
use tbclla\RevolutMerchant\Client;
8
9
class RevolutMerchantServiceProvider extends ServiceProvider
10
{
11
	/**
12
	 * Register services.
13
	 *
14
	 * @return void
15
	 */
16
	public function register()
17
	{
18
		$this->app->singleton('merchant', function() {
19
			return new Client(config('revolut-merchant.api_key'));
20
		});
21
	}
22
23
	/**
24
	 * Bootstrap services.
25
	 *
26
	 * @return void
27
	 */
28
	public function boot()
29
	{
30
		$this->publishes([
31
			__DIR__ . '/../config/revolut-merchant.php' => config_path('revolut-merchant.php')
32
		]);
33
34
		Blade::directive('revolutMerchantScript', function() {
35
36
			$src = config('revolut-merchant.sandbox', true)
37
				? 'https://sandbox-merchant.revolut.com/embed.js'
38
				: 'https://merchant.revolut.com/embed.js';
39
40
			return '<script>!function(e,o,n){e[n]=function(t){var r=o.createElement("script");r.id="revolut-checkout",r.src="' . $src . '",r.async=!0,o.head.appendChild(r);var c={then:function(c,i){r.onload=function(){c(e[n](t))},r.onerror=function(){o.head.removeChild(r),i&&i(new Error(n+" is failed to load"))}}};return"function"==typeof Promise?Promise.resolve(c):c}}(window,document,"RevolutCheckout");</script>';
41
		});
42
	}
43
}
44