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