Jake Vanderwerf
2026-03-03 772462eeca3002a1d52508aeba485aab2b4742ad
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
<?php
namespace JVBase\managers\SEO\render\Traits\_Properties;
 
use JVBase\managers\SEO\render\Traits\_Helpers\arrayHelper;
 
if (!defined('ABSPATH')) {
    exit;
}
trait paymentMethodTrait {
    use arrayHelper;
    /**
     * @var array|string The payment method(s) that are accepted in general by an organization, or for some specific demand or offer.
     */
    protected array|string $paymentMethod;
 
    protected array $mappedMethods = [
        'banktransfer'  => 'http://purl.org/goodrelations/v1#ByBankTransferInAdvance',
        'invoice'       => 'http://purl.org/goodrelations/v1#ByInvoice',
        'cash'          => 'http://purl.org/goodrelations/v1#Cash',
        'check'         => 'http://purl.org/goodrelations/v1#CheckInAdvance',
        'cod'           => 'http://purl.org/goodrelations/v1#COD',
        'directdebit'   => 'http://purl.org/goodrelations/v1#DirectDebit',
        'google'        => 'http://purl.org/goodrelations/v1#GoogleCheckout',
        'paypal'        => 'http://purl.org/goodrelations/v1#PayPal',
        'payswarm'      => 'http://purl.org/goodrelations/v1#PaySwarm',
        'amex'          => 'http://purl.org/goodrelations/v1#AmericanExpress',
        'dinersclub'    => 'http://purl.org/goodrelations/v1#DinersClub',
        'discover'      => 'http://purl.org/goodrelations/v1#Discover',
        'mastercard'    => 'http://purl.org/goodrelations/v1#MasterCard',
        'visa'          => 'http://purl.org/goodrelations/v1#VISA',
        'jcb'           => 'http://purl.org/goodrelations/v1#JCB'
    ];
 
    public function getPaymentMethod():array|string|null
    {
        return $this->paymentMethod??null;
    }
    public function setPaymentMethod(array|string $paymentMethod):void
    {
        if (!is_array($paymentMethod)) {
            $paymentMethod = [$paymentMethod];
        }
        $paymentMethod = $this->testAllowed('paymentMethod', $this->mappedMethods, $paymentMethod);
        if (empty($paymentMethod)) {
            return;
        }
        if (count($paymentMethod) === 1) {
            $paymentMethod = $paymentMethod[0];
        }
        $this->paymentMethod = $paymentMethod;
    }
 
    public function formatPaymentMethod():array|null
    {
        if (!isset($this->paymentMethod)) {
            return null;
        }
        if (is_array($this->paymentMethod)) {
            return array_map(function($method) {
                return ['@id' => $method];
            }, $this->paymentMethod);
        } else {
            return ['@id' => $this->paymentMethod];
        }
    }
 
    public function getPaymentMethodFieldConfig():array
    {
        return [
            'type'  => 'checkbox',
            'label' => 'Payment Methods',
            'options'   => array_keys($this->mappedMethods)
        ];
    }
}