CreateCheckoutSession.php
4 years ago
CreatePaymentIntent.php
4 years ago
GetOrCreateStripeCustomer.php
4 years ago
GetPaymentMethodFromRequest.php
4 years ago
SaveDonationSummary.php
4 years ago
UpdateStripeAccountStatementDescriptor.php
4 years ago
ValidatePaymentMethod.php
4 years ago
GetOrCreateStripeCustomer.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\PaymentGateways\Gateways\Stripe\Actions; |
| 4 | |
| 5 | use Give\PaymentGateways\DataTransferObjects\GatewayPaymentData; |
| 6 | use Give\PaymentGateways\Gateways\Stripe\Exceptions\StripeCustomerException; |
| 7 | use Give_Stripe_Customer; |
| 8 | |
| 9 | class GetOrCreateStripeCustomer |
| 10 | { |
| 11 | |
| 12 | /** |
| 13 | * @since 2.20.0 add second param support to function. |
| 14 | * This param is optional because we use it only when donor subscribe for recurring donation. |
| 15 | * @since 2.19.0 |
| 16 | * |
| 17 | * @param GatewayPaymentData $stripePaymentMethodId |
| 18 | * @param string $stripePaymentMethopdId |
| 19 | * |
| 20 | * @return Give_Stripe_Customer |
| 21 | * @throws StripeCustomerException |
| 22 | */ |
| 23 | public function __invoke(GatewayPaymentData $paymentData, $stripePaymentMethodId = '') |
| 24 | { |
| 25 | $giveStripeCustomer = new Give_Stripe_Customer($paymentData->donorInfo->email, $stripePaymentMethodId); |
| 26 | |
| 27 | if (!$giveStripeCustomer->get_id()) { |
| 28 | throw new StripeCustomerException(__('Unable to find or create stripe customer object.', 'give')); |
| 29 | } |
| 30 | |
| 31 | $this->saveStripeCustomerId($paymentData->donationId, $giveStripeCustomer->get_id()); |
| 32 | |
| 33 | return $giveStripeCustomer; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @since 2.19.0 |
| 38 | * |
| 39 | * @param int $donationId |
| 40 | * @param string $stripeCustomerId |
| 41 | * |
| 42 | * @return void |
| 43 | */ |
| 44 | protected function saveStripeCustomerId($donationId, $stripeCustomerId) |
| 45 | { |
| 46 | $donor = new \Give_Donor( |
| 47 | give_get_payment_donor_id($donationId) |
| 48 | ); |
| 49 | |
| 50 | $donor->update_meta(give_stripe_get_customer_key(), $stripeCustomerId); |
| 51 | |
| 52 | give_insert_payment_note( |
| 53 | $donationId, |
| 54 | sprintf(__('Stripe Customer ID: %s', 'give'), $stripeCustomerId) |
| 55 | ); |
| 56 | |
| 57 | give_update_meta($donationId, give_stripe_get_customer_key(), $stripeCustomerId); |
| 58 | } |
| 59 | } |
| 60 |