-
Notifications
You must be signed in to change notification settings - Fork 193
/
TestGateway.php
108 lines (93 loc) · 2.68 KB
/
TestGateway.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Give\PaymentGateways\Gateways\TestGateway;
use Give\Donations\Models\Donation;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Commands\PaymentComplete;
use Give\Framework\PaymentGateways\Commands\PaymentRefunded;
use Give\Framework\PaymentGateways\PaymentGateway;
use Give\Framework\Support\Facades\Scripts\ScriptAsset;
use Give\Helpers\Form\Utils as FormUtils;
use Give\Helpers\Language;
use Give\PaymentGateways\Gateways\TestGateway\Views\LegacyFormFieldMarkup;
/**
* A gateway for testing the donation process. No actual payment is processed and only form validation is performed.
*
* @since 3.0.0 change to Test Donations and manual id to replace legacy gateway
* @since 2.18.0
*/
class TestGateway extends PaymentGateway
{
/**
* @inheritDoc
*/
public static function id(): string
{
return 'manual';
}
/**
* @inheritDoc
*/
public function getId(): string
{
return self::id();
}
/**
* @inheritDoc
*/
public function getName(): string
{
return __('Test Donation', 'give');
}
/**
* @since 2.32.0 updated to enqueue script
* @since 2.30.0
*/
public function enqueueScript(int $formId)
{
$scriptAsset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/testGateway.asset.php');
wp_enqueue_script(
$this::id(),
GIVE_PLUGIN_URL . 'build/testGateway.js',
$scriptAsset['dependencies'],
$scriptAsset['version'],
true
);
Language::setScriptTranslations($this::id());
}
/**
* @inheritDoc
*/
public function getPaymentMethodLabel(): string
{
return __('Test Donation', 'give');
}
/**
* @since 2.18.0
*/
public function getLegacyFormFieldMarkup(int $formId, array $args): string
{
if (FormUtils::isLegacyForm($formId)) {
return '';
}
/** @var LegacyFormFieldMarkup $legacyFormFieldMarkup */
$legacyFormFieldMarkup = give(LegacyFormFieldMarkup::class);
return $legacyFormFieldMarkup();
}
/**
* @inheritDoc
*/
public function createPayment(Donation $donation, $gatewayData): GatewayCommand
{
$intent = $gatewayData['testGatewayIntent'] ?? 'test-gateway-intent';
return new PaymentComplete("test-gateway-transaction-id-{$intent}-$donation->id");
}
/**
* @since 2.29.0 Return PaymentRefunded instead of a bool value
* @since 2.20.0
* @inerhitDoc
*/
public function refundDonation(Donation $donation): PaymentRefunded
{
return new PaymentRefunded();
}
}