give
/
src
/
PaymentGateways
/
Gateways
/
Stripe
/
StripePaymentElementGateway
/
DataTransferObjects
/
StripePaymentIntentData.php
give
/
src
/
PaymentGateways
/
Gateways
/
Stripe
/
StripePaymentElementGateway
/
DataTransferObjects
Last commit date
StripeGatewayData.php
2 years ago
StripePaymentIntentData.php
1 year ago
StripePaymentIntentData.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\Stripe\StripePaymentElementGateway\DataTransferObjects; |
| 4 | |
| 5 | class StripePaymentIntentData |
| 6 | { |
| 7 | /** |
| 8 | * @var string |
| 9 | */ |
| 10 | public $amount; |
| 11 | /** |
| 12 | * @var string |
| 13 | */ |
| 14 | public $currency; |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | public $customer; |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | public $description; |
| 23 | /** |
| 24 | * @var array |
| 25 | */ |
| 26 | public $metadata; |
| 27 | /** |
| 28 | * @var array|null |
| 29 | * |
| 30 | */ |
| 31 | public $automaticPaymentMethods; |
| 32 | /** |
| 33 | * @var string|null |
| 34 | */ |
| 35 | public $applicationFeeAmount; |
| 36 | /** |
| 37 | * @var string|null |
| 38 | */ |
| 39 | public $receiptEmail; |
| 40 | |
| 41 | /** |
| 42 | * @since 3.20.0 removed statement_descriptor. As of 01/02/2024, Stripe no longer supports the `statement_descriptor` parameter on the PaymentIntent API for PaymentIntents in which one of the supported `payment_method_types` is `card`. |
| 43 | * @since 3.0.0 |
| 44 | * |
| 45 | * @param array{amount: string, currency: string, customer: string, description: string, metadata: array, automatic_payment_methods: array, application_fee_amount: string, receipt_email: string } $array |
| 46 | */ |
| 47 | public static function fromArray(array $array): self |
| 48 | { |
| 49 | $self = new self(); |
| 50 | $self->amount = $array['amount']; |
| 51 | $self->currency = $array['currency']; |
| 52 | $self->customer = $array['customer']; |
| 53 | $self->description = $array['description']; |
| 54 | $self->metadata = $array['metadata']; |
| 55 | $self->automaticPaymentMethods = !empty($array['automatic_payment_methods']) ? $array['automatic_payment_methods'] : null; |
| 56 | $self->applicationFeeAmount = !empty($array['application_fee_amount']) ? $array['application_fee_amount'] : null; |
| 57 | $self->receiptEmail = !empty($array['receipt_email']) ? $array['receipt_email'] : null; |
| 58 | |
| 59 | return $self; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @since 3.0.0 |
| 64 | */ |
| 65 | public function toParams() |
| 66 | { |
| 67 | $args = [ |
| 68 | 'amount' => $this->amount, |
| 69 | 'currency' => $this->currency, |
| 70 | 'customer' => $this->customer, |
| 71 | 'description' => $this->description, |
| 72 | 'metadata' => $this->metadata |
| 73 | ]; |
| 74 | |
| 75 | if ($this->automaticPaymentMethods){ |
| 76 | $args['automatic_payment_methods'] = $this->automaticPaymentMethods; |
| 77 | } |
| 78 | |
| 79 | if ($this->applicationFeeAmount){ |
| 80 | $args['application_fee_amount'] = $this->applicationFeeAmount; |
| 81 | } |
| 82 | |
| 83 | if ($this->receiptEmail){ |
| 84 | $args['receipt_email'] = $this->receiptEmail; |
| 85 | } |
| 86 | |
| 87 | return apply_filters( |
| 88 | 'givewp_stripe_create_intent_args', |
| 89 | $args |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @since 3.0.0 |
| 95 | */ |
| 96 | public function toOptions(string $stripeConnectAccountId): array |
| 97 | { |
| 98 | return ['stripe_account' => $stripeConnectAccountId]; |
| 99 | } |
| 100 | } |
| 101 |