| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\PaymentGateways\Gateways\Stripe; |
| 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\Exceptions\PaymentGatewayException; |
| 9 |
use Give\Framework\PaymentGateways\PaymentGateway; |
| 10 |
use Give\Framework\PaymentGateways\SubscriptionModule; |
| 11 |
use Give\Helpers\Call; |
| 12 |
use Give\PaymentGateways\Gateways\Stripe\Traits\HandlePaymentIntentStatus; |
| 13 |
use Give\PaymentGateways\Gateways\Stripe\Traits\SEPAMandateForm; |
| 14 |
use Give\PaymentGateways\Gateways\Stripe\ValueObjects\PaymentMethod; |
| 15 |
|
| 16 |
/** |
| 17 |
* @since 2.19.0 |
| 18 |
*/ |
| 19 |
class SEPAGateway extends PaymentGateway |
| 20 |
{ |
| 21 |
use SEPAMandateForm; |
| 22 |
use HandlePaymentIntentStatus; |
| 23 |
|
| 24 |
/** @var array */ |
| 25 |
protected $errorMessages = []; |
| 26 |
|
| 27 |
/** |
| 28 |
* @param SubscriptionModule|null $subscriptionModule |
| 29 |
* @since 4.17.0 Declare the nullable parameter explicitly. |
| 30 |
*/ |
| 31 |
public function __construct(?SubscriptionModule $subscriptionModule = null) |
| 32 |
{ |
| 33 |
parent::__construct($subscriptionModule); |
| 34 |
|
| 35 |
$this->errorMessages['accountConfiguredNoSsl'] = esc_html__( |
| 36 |
'IBAN fields are disabled because your site is not running securely over HTTPS.', |
| 37 |
'give' |
| 38 |
); |
| 39 |
$this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__( |
| 40 |
'IBAN fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.', |
| 41 |
'give' |
| 42 |
); |
| 43 |
$this->errorMessages['accountNotConfigured'] = esc_html__( |
| 44 |
'IBAN fields are disabled. Please connect and configure your Stripe account to accept donations.', |
| 45 |
'give' |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* @inheritDoc |
| 51 |
* @since 2.19.7 fix handlePaymentIntentStatus not receiving extra param |
| 52 |
* @since 2.19.0 |
| 53 |
* |
| 54 |
* @param array{stripePaymentMethod: PaymentMethod} $gatewayData |
| 55 |
* |
| 56 |
* @return GatewayCommand |
| 57 |
* @throws PaymentGatewayException |
| 58 |
*/ |
| 59 |
public function createPayment(Donation $donation, $gatewayData): GatewayCommand |
| 60 |
{ |
| 61 |
|
| 62 |
$donationSummary = Call::invoke(Actions\SaveDonationSummary::class, $donation); |
| 63 |
$stripeCustomer = Call::invoke(Actions\GetOrCreateStripeCustomer::class, $donation); |
| 64 |
|
| 65 |
$createIntentAction = new Actions\CreatePaymentIntent($this->getPaymentIntentArgs()); |
| 66 |
|
| 67 |
return $this->handlePaymentIntentStatus( |
| 68 |
$createIntentAction( |
| 69 |
$donation, |
| 70 |
$donationSummary, |
| 71 |
$stripeCustomer, |
| 72 |
$gatewayData['stripePaymentMethod'] |
| 73 |
), |
| 74 |
$donation |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* @inheritDoc |
| 80 |
*/ |
| 81 |
public static function id(): string |
| 82 |
{ |
| 83 |
return 'stripe_sepa'; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* @inheritDoc |
| 88 |
*/ |
| 89 |
public function getId(): string |
| 90 |
{ |
| 91 |
return self::id(); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* @inheritDoc |
| 96 |
*/ |
| 97 |
public function getName(): string |
| 98 |
{ |
| 99 |
return __('Stripe - SEPA Direct Debit', 'give'); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* @inheritDoc |
| 104 |
*/ |
| 105 |
public function getPaymentMethodLabel(): string |
| 106 |
{ |
| 107 |
return __('Stripe - SEPA Direct Debit', 'give'); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* @inheritDoc |
| 112 |
*/ |
| 113 |
public function getLegacyFormFieldMarkup(int $formId, array $args): string |
| 114 |
{ |
| 115 |
return $this->getMandateFormHTML($formId, $args); |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* @since 2.33.5 Use give_get_ip() instead of give_stripe_get_ip_address() |
| 120 |
* @since 2.19.0 |
| 121 |
* @return array |
| 122 |
*/ |
| 123 |
protected function getPaymentIntentArgs(): array |
| 124 |
{ |
| 125 |
return [ |
| 126 |
'payment_method_types' => ['sepa_debit'], |
| 127 |
'setup_future_usage' => 'on_session', |
| 128 |
'mandate_data' => [ |
| 129 |
'customer_acceptance' => [ |
| 130 |
'type' => 'online', |
| 131 |
'online' => [ |
| 132 |
'ip_address' => give_get_ip(), |
| 133 |
'user_agent' => give_get_user_agent(), |
| 134 |
], |
| 135 |
], |
| 136 |
], |
| 137 |
]; |
| 138 |
} |
| 139 |
} |
| 140 |
|