From 5fb494651fee32c35523830d1dee59699bb76af1 Mon Sep 17 00:00:00 2001 From: Dave Earley Date: Wed, 7 Aug 2024 03:45:16 +0100 Subject: [PATCH] Revert "Send customer data and order metadata to Stripe" --- .../StripeCustomerDomainObjectAbstract.php | 118 ------------------ .../StripeCustomerDomainObject.php | 7 -- backend/app/Models/StripeCustomer.php | 16 --- .../Providers/RepositoryServiceProvider.php | 6 +- .../Eloquent/StripeCustomerRepository.php | 20 --- .../StripeCustomerRepositoryInterface.php | 14 --- .../DTOs/CreatePaymentIntentRequestDTO.php | 2 - .../StripePaymentIntentCreationService.php | 68 +--------- .../Stripe/CreatePaymentIntentHandler.php | 1 - ...7_005807_create_stripe_customers_table.php | 26 ---- 10 files changed, 7 insertions(+), 271 deletions(-) delete mode 100644 backend/app/DomainObjects/Generated/StripeCustomerDomainObjectAbstract.php delete mode 100644 backend/app/DomainObjects/StripeCustomerDomainObject.php delete mode 100644 backend/app/Models/StripeCustomer.php delete mode 100644 backend/app/Repository/Eloquent/StripeCustomerRepository.php delete mode 100644 backend/app/Repository/Interfaces/StripeCustomerRepositoryInterface.php delete mode 100644 backend/database/migrations/2024_08_07_005807_create_stripe_customers_table.php diff --git a/backend/app/DomainObjects/Generated/StripeCustomerDomainObjectAbstract.php b/backend/app/DomainObjects/Generated/StripeCustomerDomainObjectAbstract.php deleted file mode 100644 index 66b6f685..00000000 --- a/backend/app/DomainObjects/Generated/StripeCustomerDomainObjectAbstract.php +++ /dev/null @@ -1,118 +0,0 @@ - $this->id ?? null, - 'name' => $this->name ?? null, - 'email' => $this->email ?? null, - 'stripe_customer_id' => $this->stripe_customer_id ?? null, - 'created_at' => $this->created_at ?? null, - 'updated_at' => $this->updated_at ?? null, - 'deleted_at' => $this->deleted_at ?? null, - ]; - } - - public function setId(int $id): self - { - $this->id = $id; - return $this; - } - - public function getId(): int - { - return $this->id; - } - - public function setName(string $name): self - { - $this->name = $name; - return $this; - } - - public function getName(): string - { - return $this->name; - } - - public function setEmail(string $email): self - { - $this->email = $email; - return $this; - } - - public function getEmail(): string - { - return $this->email; - } - - public function setStripeCustomerId(string $stripe_customer_id): self - { - $this->stripe_customer_id = $stripe_customer_id; - return $this; - } - - public function getStripeCustomerId(): string - { - return $this->stripe_customer_id; - } - - public function setCreatedAt(?string $created_at): self - { - $this->created_at = $created_at; - return $this; - } - - public function getCreatedAt(): ?string - { - return $this->created_at; - } - - public function setUpdatedAt(?string $updated_at): self - { - $this->updated_at = $updated_at; - return $this; - } - - public function getUpdatedAt(): ?string - { - return $this->updated_at; - } - - public function setDeletedAt(?string $deleted_at): self - { - $this->deleted_at = $deleted_at; - return $this; - } - - public function getDeletedAt(): ?string - { - return $this->deleted_at; - } -} diff --git a/backend/app/DomainObjects/StripeCustomerDomainObject.php b/backend/app/DomainObjects/StripeCustomerDomainObject.php deleted file mode 100644 index dd4aa33f..00000000 --- a/backend/app/DomainObjects/StripeCustomerDomainObject.php +++ /dev/null @@ -1,7 +0,0 @@ - OrganizerRepository::class, AccountUserRepositoryInterface::class => AccountUserRepository::class, CapacityAssignmentRepositoryInterface::class => CapacityAssignmentRepository::class, - StripeCustomerRepositoryInterface::class => StripeCustomerRepository::class, + ReservationRepositoryInterface::class => ReservationRepository::class, ]; public function register(): void diff --git a/backend/app/Repository/Eloquent/StripeCustomerRepository.php b/backend/app/Repository/Eloquent/StripeCustomerRepository.php deleted file mode 100644 index 799203c4..00000000 --- a/backend/app/Repository/Eloquent/StripeCustomerRepository.php +++ /dev/null @@ -1,20 +0,0 @@ - - */ -interface StripeCustomerRepositoryInterface extends RepositoryInterface -{ - -} diff --git a/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php b/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php index fa27bf2e..a63c1b0d 100644 --- a/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php +++ b/backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php @@ -4,7 +4,6 @@ use HiEvents\DataTransferObjects\BaseDTO; use HiEvents\DomainObjects\AccountDomainObject; -use HiEvents\DomainObjects\OrderDomainObject; class CreatePaymentIntentRequestDTO extends BaseDTO { @@ -12,7 +11,6 @@ public function __construct( public readonly int $amount, public readonly string $currencyCode, public AccountDomainObject $account, - public OrderDomainObject $order, ) { } diff --git a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php index b88c1604..5a9f1858 100644 --- a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php +++ b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php @@ -2,26 +2,20 @@ namespace HiEvents\Services\Domain\Payment\Stripe; -use HiEvents\DomainObjects\StripeCustomerDomainObject; use HiEvents\Exceptions\Stripe\CreatePaymentIntentFailedException; -use HiEvents\Repository\Interfaces\StripeCustomerRepositoryInterface; use HiEvents\Services\Domain\Payment\Stripe\DTOs\CreatePaymentIntentRequestDTO; use HiEvents\Services\Domain\Payment\Stripe\DTOs\CreatePaymentIntentResponseDTO; use Illuminate\Config\Repository; -use Illuminate\Database\DatabaseManager; use Psr\Log\LoggerInterface; use Stripe\Exception\ApiErrorException; use Stripe\StripeClient; -use Throwable; -class StripePaymentIntentCreationService +readonly class StripePaymentIntentCreationService { public function __construct( - readonly private StripeClient $stripeClient, - readonly private LoggerInterface $logger, - readonly private Repository $config, - readonly private StripeCustomerRepositoryInterface $stripeCustomerRepository, - readonly private DatabaseManager $databaseManager, + private StripeClient $stripeClient, + private LoggerInterface $logger, + private Repository $config, ) { } @@ -53,26 +47,16 @@ public function retrievePaymentIntentClientSecret( /** * @throws CreatePaymentIntentFailedException - * @throws ApiErrorException|Throwable */ public function createPaymentIntent(CreatePaymentIntentRequestDTO $paymentIntentDTO): CreatePaymentIntentResponseDTO { try { - $this->databaseManager->beginTransaction(); - $applicationFee = $this->getApplicationFee($paymentIntentDTO); $paymentIntent = $this->stripeClient->paymentIntents->create([ 'amount' => $paymentIntentDTO->amount, 'currency' => $paymentIntentDTO->currencyCode, - 'customer' => $this->upsertStripeCustomer($paymentIntentDTO)->getStripeCustomerId(), 'setup_future_usage' => 'on_session', - 'metadata' => [ - 'order_id' => $paymentIntentDTO->order->getId(), - 'event_id' => $paymentIntentDTO->order->getEventId(), - 'order_short_id' => $paymentIntentDTO->order->getShortId(), - 'account_id' => $paymentIntentDTO->account->getId(), - ], 'automatic_payment_methods' => [ 'enabled' => true, ], @@ -84,8 +68,6 @@ public function createPaymentIntent(CreatePaymentIntentRequestDTO $paymentIntent 'paymentIntentDTO' => $paymentIntentDTO->toArray(['account']), ]); - $this->databaseManager->commit(); - return new CreatePaymentIntentResponseDTO( paymentIntentId: $paymentIntent->id, clientSecret: $paymentIntent->client_secret, @@ -100,10 +82,6 @@ public function createPaymentIntent(CreatePaymentIntentRequestDTO $paymentIntent throw new CreatePaymentIntentFailedException( __('There was an error communicating with the payment provider. Please try again later.') ); - } catch (Throwable $exception) { - $this->databaseManager->rollBack(); - - throw $exception; } } @@ -141,42 +119,4 @@ private function getStripeAccountData(CreatePaymentIntentRequestDTO $paymentInte 'stripe_account' => $paymentIntentDTO->account->getStripeAccountId() ]; } - - /** - * @throws ApiErrorException - */ - private function upsertStripeCustomer(CreatePaymentIntentRequestDTO $paymentIntentDTO): StripeCustomerDomainObject - { - $customer = $this->stripeCustomerRepository->findFirstWhere([ - 'email' => $paymentIntentDTO->order->getEmail(), - ]); - - if ($customer === null) { - $stripeCustomer = $this->stripeClient->customers->create([ - 'email' => $paymentIntentDTO->order->getEmail(), - 'name' => $paymentIntentDTO->order->getFullName(), - ]); - - return $this->stripeCustomerRepository->create([ - 'name' => $stripeCustomer->name, - 'email' => $stripeCustomer->email, - 'stripe_customer_id' => $stripeCustomer->id, - ]); - } - - if ($customer->getName() === $paymentIntentDTO->order->getFullName()) { - return $customer; - } - - $stripeCustomer = $this->stripeClient->customers->update( - $customer->getStripeCustomerId(), - ['name' => $paymentIntentDTO->order->getFullName()] - ); - - $this->stripeCustomerRepository->updateFromArray($customer->getId(), [ - 'name' => $stripeCustomer->name, - ]); - - return $customer; - } } diff --git a/backend/app/Services/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php b/backend/app/Services/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php index 30423a3e..08f6daaf 100644 --- a/backend/app/Services/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php +++ b/backend/app/Services/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php @@ -69,7 +69,6 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO 'amount' => Money::of($order->getTotalGross(), $order->getCurrency())->getMinorAmount()->toInt(), 'currencyCode' => $order->getCurrency(), 'account' => $account, - 'order' => $order, ])); $this->stripePaymentsRepository->create([ diff --git a/backend/database/migrations/2024_08_07_005807_create_stripe_customers_table.php b/backend/database/migrations/2024_08_07_005807_create_stripe_customers_table.php deleted file mode 100644 index 6b62ad4d..00000000 --- a/backend/database/migrations/2024_08_07_005807_create_stripe_customers_table.php +++ /dev/null @@ -1,26 +0,0 @@ -id(); - - $table->string('name'); - $table->string('email'); - $table->string('stripe_customer_id'); - - $table->timestamps(); - $table->softDeletes(); - }); - } - - public function down(): void - { - Schema::dropIfExists('stripe_customers'); - } -};