OfflineGateway.php
106 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\Offline; |
| 4 | |
| 5 | use Give\Donations\Models\Donation; |
| 6 | use Give\Framework\Exceptions\Primitives\RuntimeException; |
| 7 | use Give\Framework\PaymentGateways\Commands\PaymentPending; |
| 8 | use Give\Framework\PaymentGateways\PaymentGateway; |
| 9 | use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 10 | use Give\Helpers\Language; |
| 11 | use Give\PaymentGateways\Gateways\Offline\Views\LegacyFormFieldMarkup; |
| 12 | |
| 13 | /** |
| 14 | * The Offline payment gateway, intended to reflect donations that are made offline and will be later confirmed. |
| 15 | * |
| 16 | * @since 3.0.0 |
| 17 | */ |
| 18 | class OfflineGateway extends PaymentGateway |
| 19 | { |
| 20 | /** |
| 21 | * @since 3.0.0 |
| 22 | */ |
| 23 | public static function id(): string |
| 24 | { |
| 25 | return 'offline'; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @since 3.0.0 |
| 30 | */ |
| 31 | public function getId(): string |
| 32 | { |
| 33 | return self::id(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @since 3.0.0 |
| 38 | */ |
| 39 | public function getName(): string |
| 40 | { |
| 41 | return __('Offline Donation', 'give'); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @since 3.0.0 |
| 46 | */ |
| 47 | public function getPaymentMethodLabel(): string |
| 48 | { |
| 49 | return __('Offline Donation', 'give'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @since 3.0.0 |
| 54 | */ |
| 55 | public function formSettings(int $formId): array |
| 56 | { |
| 57 | return [ |
| 58 | 'markup' => (new LegacyFormFieldMarkup())($formId, false), |
| 59 | ]; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @since 3.0.0 |
| 64 | */ |
| 65 | public function enqueueScript(int $formId) |
| 66 | { |
| 67 | $scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/offlineGateway.asset.php'); |
| 68 | |
| 69 | wp_enqueue_script( |
| 70 | $this::id(), |
| 71 | GIVE_PLUGIN_URL . 'build/offlineGateway.js', |
| 72 | $scriptAsset['dependencies'], |
| 73 | $scriptAsset['version'], |
| 74 | true |
| 75 | ); |
| 76 | |
| 77 | Language::setScriptTranslations($this::id()); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @since 3.0.0 |
| 82 | */ |
| 83 | public function getLegacyFormFieldMarkup(int $formId): string |
| 84 | { |
| 85 | return (new LegacyFormFieldMarkup())($formId, true); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @since 3.0.0 |
| 90 | */ |
| 91 | public function createPayment(Donation $donation, $gatewayData): PaymentPending |
| 92 | { |
| 93 | return new PaymentPending(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @since 3.0.0 |
| 98 | */ |
| 99 | public function refundDonation(Donation $donation) |
| 100 | { |
| 101 | throw new RuntimeException( |
| 102 | 'Method has not been implemented yet. Please use the legacy method in the meantime.' |
| 103 | ); |
| 104 | } |
| 105 | } |
| 106 |