This repository has been archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.php
103 lines (90 loc) · 2.3 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
use Beebmx\KirbyPay\Payment;
use Beebmx\KirbyPay\Routes\Routes;
use Brick\Money\Context\CustomContext;
use Brick\Money\Money;
use Illuminate\Support\Collection;
if (!function_exists('pay')) {
function pay($key, $default = null)
{
return option("beebmx.kirby-pay.{$key}", $default);
}
}
if (!function_exists('kpStyle')) {
function kpStyle($key, $default = null)
{
return option('beebmx.kirby-pay.styles', $default)[$key] ?? $default;
}
}
if (!function_exists('kpStripe')) {
function kpStripe()
{
return [
'base' => array_merge(
kpStyle('stripe-input-default'),
kpStyle('stripe-input'),
),
'invalid' => array_merge(
kpStyle('stripe-invalid-default'),
kpStyle('stripe-invalid'),
),
];
}
}
if (!function_exists('kpT')) {
function kpT($key, $default = null)
{
return t('beebmx.kirby-pay.' . $key, $default);
}
}
if (!function_exists('kpUrl')) {
function kpUrl($key)
{
return Routes::getRoutePathByName($key);
}
}
if (!function_exists('kpMethod')) {
function kpMethod($key)
{
return Routes::getRouteMethodByName($key);
}
}
if (!function_exists('kpPaymentMethods')) {
function kpPaymentMethods()
{
$methods = Payment::getPaymentMethods();
return (new Collection(pay('payment_types')))
->filter(function ($method) use ($methods) {
return (in_array($method, $methods));
})->values()->toArray();
}
}
if (!function_exists('kpInDevelopment')) {
function kpInDevelopment()
{
return in_array(pay('env', 'production'), ['test', 'local']);
}
}
if (!function_exists('kpGetFirstPaymentMethod')) {
function kpGetFirstPaymentMethod()
{
return kpPaymentMethods()[0] ?? 'card';
}
}
if (!function_exists('kpHasShipping')) {
function kpHasShipping(): bool
{
return pay('shipping', false);
}
}
if (!function_exists('kpParseMoney')) {
function kpParseMoney($value) {
return Money::of(
$value,
strtoupper(pay('currency', 'usd')),
new CustomContext(pay('money_precision', 2))
)->formatTo(
pay('locale', 'en_US')
);
}
}