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
BECSGateway.php
121 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 | use Give\PaymentGateways\Gateways\Stripe\Traits\BECSMandateForm; |
| 12 | use Give\PaymentGateways\Gateways\Stripe\Traits\HandlePaymentIntentStatus; |
| 13 | |
| 14 | /** |
| 15 | * @since 2.19.0 |
| 16 | */ |
| 17 | class BECSGateway extends PaymentGateway |
| 18 | { |
| 19 | use BECSMandateForm; |
| 20 | use HandlePaymentIntentStatus; |
| 21 | |
| 22 | /** @var array */ |
| 23 | protected $errorMessages = []; |
| 24 | |
| 25 | public function __construct(SubscriptionModuleInterface $subscriptionModule = null) |
| 26 | { |
| 27 | parent::__construct($subscriptionModule); |
| 28 | |
| 29 | $this->errorMessages['accountConfiguredNoSsl'] = esc_html__( 'Mandate form fields are disabled because your site is not running securely over HTTPS.', 'give' ); |
| 30 | $this->errorMessages['accountNotConfiguredNoSsl'] = esc_html__( 'Mandate form fields are disabled because Stripe is not connected and your site is not running securely over HTTPS.', 'give' ); |
| 31 | $this->errorMessages['accountNotConfigured'] = esc_html__( 'Mandate form fields are disabled. Please connect and configure your Stripe account to accept donations.', 'give' ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @inheritDoc |
| 36 | * @since 2.19.7 fix handlePaymentIntentStatus not receiving extra param |
| 37 | * @since 2.19.0 |
| 38 | * @return GatewayCommand |
| 39 | * @throws PaymentGatewayException |
| 40 | */ |
| 41 | public function createPayment( GatewayPaymentData $paymentData ) |
| 42 | { |
| 43 | $paymentMethod = Call::invoke( Actions\GetPaymentMethodFromRequest::class, $paymentData ); |
| 44 | $donationSummary = Call::invoke( Actions\SaveDonationSummary::class, $paymentData ); |
| 45 | $stripeCustomer = Call::invoke( Actions\GetOrCreateStripeCustomer::class, $paymentData ); |
| 46 | |
| 47 | $createIntentAction = new Actions\CreatePaymentIntent( $this->getPaymentIntentArgs() ); |
| 48 | |
| 49 | return $this->handlePaymentIntentStatus( |
| 50 | $createIntentAction( |
| 51 | $paymentData, |
| 52 | $donationSummary, |
| 53 | $stripeCustomer, |
| 54 | $paymentMethod |
| 55 | ), |
| 56 | $paymentData->donationId |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @inheritDoc |
| 62 | */ |
| 63 | public static function id() |
| 64 | { |
| 65 | return 'stripe_becs'; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inheritDoc |
| 70 | */ |
| 71 | public function getId() |
| 72 | { |
| 73 | return self::id(); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @inheritDoc |
| 78 | */ |
| 79 | public function getName() |
| 80 | { |
| 81 | return __('Stripe - BECS Direct Debit', 'give'); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @inheritDoc |
| 86 | */ |
| 87 | public function getPaymentMethodLabel() |
| 88 | { |
| 89 | return __('Stripe - BECS Direct Debit', 'give'); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @inheritDoc |
| 94 | */ |
| 95 | public function getLegacyFormFieldMarkup($formId, $args) |
| 96 | { |
| 97 | return $this->getMandateFormHTML( $formId, $args ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @since 2.19.0 |
| 102 | * @return array |
| 103 | */ |
| 104 | protected function getPaymentIntentArgs() |
| 105 | { |
| 106 | return [ |
| 107 | 'payment_method_types' => [ 'au_becs_debit' ], |
| 108 | 'setup_future_usage' => 'off_session', // @TODO Is this correct? Maybe should be `on_session` - need to confirm. |
| 109 | 'mandate_data' => [ |
| 110 | 'customer_acceptance' => [ |
| 111 | 'type' => 'online', |
| 112 | 'online' => [ |
| 113 | 'ip_address' => give_stripe_get_ip_address(), |
| 114 | 'user_agent' => give_get_user_agent(), |
| 115 | ], |
| 116 | ], |
| 117 | ], |
| 118 | ]; |
| 119 | } |
| 120 | } |
| 121 |