Actions
4 years ago
Controllers
4 years ago
Exceptions
4 years ago
Helpers
4 years ago
Migrations
4 years ago
Traits
4 years ago
ValueObjects
4 years ago
BECSGateway.php
4 years ago
CheckoutGateway.php
4 years ago
CreditCardGateway.php
4 years ago
SEPAGateway.php
4 years ago
CreditCardGateway.php
107 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\Stripe; |
| 4 | |
| 5 | use Give\Framework\PaymentGateways\Commands\GatewayCommand; |
| 6 | use Give\Framework\PaymentGateways\Contracts\SubscriptionModuleInterface; |
| 7 | use Give\Framework\PaymentGateways\Exceptions\PaymentGatewayException; |
| 8 | use Give\Framework\PaymentGateways\PaymentGateway; |
| 9 | use Give\Helpers\Call; |
| 10 | use Give\PaymentGateways\DataTransferObjects\GatewayPaymentData; |
| 11 | |
| 12 | /** |
| 13 | * @since 2.19.0 |
| 14 | */ |
| 15 | class CreditCardGateway extends PaymentGateway |
| 16 | { |
| 17 | use Traits\CreditCardForm; |
| 18 | use Traits\HandlePaymentIntentStatus; |
| 19 | |
| 20 | /** @var array */ |
| 21 | protected $errorMessages = []; |
| 22 | |
| 23 | public function __construct(SubscriptionModuleInterface $subscriptionModule = null) |
| 24 | { |
| 25 | parent::__construct($subscriptionModule); |
| 26 | |
| 27 | $this->errorMessages['accountConfiguredNoSsl'] = esc_html__( |
| 28 | 'Credit Card fields are disabled because your site is not running securely over HTTPS.', |
| 29 | 'give' |
| 30 | ); |
| 31 | $this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__( |
| 32 | 'Credit Card fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.', |
| 33 | 'give' |
| 34 | ); |
| 35 | $this->errorMessages['accountNotConfigured'] = esc_html__( |
| 36 | 'Credit Card fields are disabled. Please connect and configure your Stripe account to accept donations.', |
| 37 | 'give' |
| 38 | ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @inheritDoc |
| 43 | * @since 2.19.7 fix handlePaymentIntentStatus not receiving extra param |
| 44 | * @since 2.19.0 |
| 45 | * @return GatewayCommand |
| 46 | * @throws PaymentGatewayException |
| 47 | */ |
| 48 | public function createPayment(GatewayPaymentData $paymentData) |
| 49 | { |
| 50 | $paymentMethod = Call::invoke( Actions\GetPaymentMethodFromRequest::class, $paymentData ); |
| 51 | $donationSummary = Call::invoke( Actions\SaveDonationSummary::class, $paymentData ); |
| 52 | $stripeCustomer = Call::invoke( Actions\GetOrCreateStripeCustomer::class, $paymentData ); |
| 53 | |
| 54 | $createIntentAction = new Actions\CreatePaymentIntent([]); |
| 55 | |
| 56 | return $this->handlePaymentIntentStatus( |
| 57 | $createIntentAction( |
| 58 | $paymentData, |
| 59 | $donationSummary, |
| 60 | $stripeCustomer, |
| 61 | $paymentMethod |
| 62 | ), |
| 63 | $paymentData->donationId |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @inheritDoc |
| 69 | */ |
| 70 | public static function id() |
| 71 | { |
| 72 | return 'stripe'; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @inheritDoc |
| 77 | */ |
| 78 | public function getId() |
| 79 | { |
| 80 | return self::id(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @inheritDoc |
| 85 | */ |
| 86 | public function getName() |
| 87 | { |
| 88 | return __('Stripe - Credit Card', 'give'); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @inheritDoc |
| 93 | */ |
| 94 | public function getPaymentMethodLabel() |
| 95 | { |
| 96 | return __('Stripe - Credit Card', 'give'); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @inheritDoc |
| 101 | */ |
| 102 | public function getLegacyFormFieldMarkup($formId, $args) |
| 103 | { |
| 104 | return $this->getCreditCardFormHTML($formId, $args); |
| 105 | } |
| 106 | } |
| 107 |