<?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)
|
];
|
}
|
}
|