1 | <?php |
||
2 | |||
3 | namespace Robbie\SilverstripeChec; |
||
4 | |||
5 | use SilverStripe\Core\Config\Configurable; |
||
6 | use SilverStripe\Core\Convert; |
||
7 | |||
8 | class ChecShortcode |
||
9 | { |
||
10 | use Configurable; |
||
11 | |||
12 | /** |
||
13 | * Path to Chec embeddable checkout JavaScript file |
||
14 | * |
||
15 | * @config |
||
16 | * @var string |
||
17 | */ |
||
18 | private static $javascript_url = 'https://assets.chec-cdn.com/js/embed.js'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | |||
20 | /** |
||
21 | * Domain for hosted Chec checkout |
||
22 | * |
||
23 | * @config |
||
24 | * @var string |
||
25 | */ |
||
26 | private static $checkout_domain = 'https://checkout.chec.io'; |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | /** |
||
29 | * ShortCode which adds a link to a Chec buy now popup window |
||
30 | * |
||
31 | * @param array $arguments |
||
32 | * @param string $content |
||
33 | * @return string |
||
34 | */ |
||
35 | public static function getBuyNowButton($arguments, $content = null): string |
||
36 | { |
||
37 | if (isset($arguments['permalink'])) { |
||
38 | $id = Convert::raw2att($arguments['permalink']); |
||
39 | unset($arguments['permalink']); |
||
40 | $siteURL = self::config()->get('checkout_domain'); |
||
41 | |||
42 | $link = "<a href=\"$siteURL/{$id}\""; |
||
43 | // Add all arguments as-is as we could potentially be receiving css class styles |
||
44 | foreach ($arguments as $key => $val) { |
||
45 | $val = Convert::raw2att($val); |
||
46 | $link .= " {$key}=\"{$val}\" "; |
||
47 | } |
||
48 | $link .= ">{$content}</a>"; |
||
49 | return $link; |
||
50 | } |
||
51 | return ''; |
||
52 | } |
||
53 | } |
||
54 |