-
Notifications
You must be signed in to change notification settings - Fork 192
/
CreditCardGateway.php
119 lines (104 loc) · 3.24 KB
/
CreditCardGateway.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
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Give\PaymentGateways\Gateways\Stripe;
use Give\Donations\Models\Donation;
use Give\Framework\Exceptions\Primitives\Exception;
use Give\Framework\PaymentGateways\Commands\GatewayCommand;
use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException;
use Give\Framework\PaymentGateways\PaymentGateway;
use Give\Framework\PaymentGateways\SubscriptionModule;
use Give\Helpers\Call;
use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentMethod;
/**
* @since 2.19.0
*/
class CreditCardGateway extends PaymentGateway
{
use Traits\CreditCardForm;
use Traits\HandlePaymentIntentStatus;
/** @var array */
protected $errorMessages = [];
public function __construct(SubscriptionModule $subscriptionModule = null)
{
parent::__construct($subscriptionModule);
$this->errorMessages['accountConfiguredNoSsl'] = esc_html__(
'Credit Card fields are disabled because your site is not running securely over HTTPS.',
'give'
);
$this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__(
'Credit Card fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.',
'give'
);
$this->errorMessages['accountNotConfigured'] = esc_html__(
'Credit Card fields are disabled. Please connect and configure your Stripe account to accept donations.',
'give'
);
}
/**
* @inheritDoc
* @since 2.19.7 fix handlePaymentIntentStatus not receiving extra param
* @since 2.19.0
*
* @param array{stripePaymentMethod: PaymentMethod} $gatewayData
*
* @throws PaymentGatewayException
*/
public function createPayment(Donation $donation, $gatewayData): GatewayCommand
{
$donationSummary = Call::invoke(Actions\SaveDonationSummary::class, $donation);
$stripeCustomer = Call::invoke(Actions\GetOrCreateStripeCustomer::class, $donation);
$createIntentAction = new Actions\CreatePaymentIntent([]);
return $this->handlePaymentIntentStatus(
$createIntentAction(
$donation,
$donationSummary,
$stripeCustomer,
$gatewayData['stripePaymentMethod']
),
$donation
);
}
/**
* @inheritDoc
*/
public static function id(): string
{
return 'stripe';
}
/**
* @inheritDoc
*/
public function getId(): string
{
return self::id();
}
/**
* @inheritDoc
*/
public function getName(): string
{
return __('Stripe - Credit Card', 'give');
}
/**
* @inheritDoc
*/
public function getPaymentMethodLabel(): string
{
return __('Stripe - Credit Card', 'give');
}
/**
* @inheritDoc
*/
public function getLegacyFormFieldMarkup(int $formId, array $args): string
{
return $this->getCreditCardFormHTML($formId, $args);
}
/**
* @since 2.20.0
* @inerhitDoc
* @throws Exception
*/
public function refundDonation(Donation $donation)
{
throw new Exception('Method has not been implemented yet. Please use the legacy method in the meantime.');
}
}