TestGateway.php
86 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\TestGateway; |
| 4 | |
| 5 | use Give\Donations\Models\Donation; |
| 6 | use Give\Framework\Exceptions\Primitives\Exception; |
| 7 | use Give\Framework\PaymentGateways\Commands\GatewayCommand; |
| 8 | use Give\Framework\PaymentGateways\Commands\PaymentComplete; |
| 9 | use Give\Framework\PaymentGateways\PaymentGateway; |
| 10 | use Give\Helpers\Form\Utils as FormUtils; |
| 11 | use Give\PaymentGateways\Gateways\TestGateway\Views\LegacyFormFieldMarkup; |
| 12 | |
| 13 | /** |
| 14 | * Class TestGateway |
| 15 | * @since 2.18.0 |
| 16 | */ |
| 17 | class TestGateway extends PaymentGateway |
| 18 | { |
| 19 | /** |
| 20 | * @inheritDoc |
| 21 | */ |
| 22 | public static function id(): string |
| 23 | { |
| 24 | return 'test-gateway'; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @inheritDoc |
| 29 | */ |
| 30 | public function getId(): string |
| 31 | { |
| 32 | return self::id(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @inheritDoc |
| 37 | */ |
| 38 | public function getName(): string |
| 39 | { |
| 40 | return __('Test Gateway', 'give'); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @inheritDoc |
| 45 | */ |
| 46 | public function getPaymentMethodLabel(): string |
| 47 | { |
| 48 | return __('Test Gateway', 'give'); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @inheritDoc |
| 53 | */ |
| 54 | public function getLegacyFormFieldMarkup(int $formId, array $args): string |
| 55 | { |
| 56 | if (FormUtils::isLegacyForm($formId)) { |
| 57 | return ''; |
| 58 | } |
| 59 | |
| 60 | /** @var LegacyFormFieldMarkup $legacyFormFieldMarkup */ |
| 61 | $legacyFormFieldMarkup = give(LegacyFormFieldMarkup::class); |
| 62 | |
| 63 | return $legacyFormFieldMarkup(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @inheritDoc |
| 68 | */ |
| 69 | public function createPayment(Donation $donation, $gatewayData = null): GatewayCommand |
| 70 | { |
| 71 | $transactionId = "test-gateway-transaction-id-{$donation->id}"; |
| 72 | |
| 73 | return new PaymentComplete($transactionId); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @since 2.20.0 |
| 78 | * @inerhitDoc |
| 79 | * @throws Exception |
| 80 | */ |
| 81 | public function refundDonation(Donation $donation) |
| 82 | { |
| 83 | throw new Exception('Method has not been implemented yet. Please use the legacy method in the meantime.'); |
| 84 | } |
| 85 | } |
| 86 |