Skip to content

Commit

Permalink
Merge pull request #127 from HiEventsDev/develop
Browse files Browse the repository at this point in the history
Revert "Send customer data and order metadata to Stripe"
  • Loading branch information
daveearley authored Aug 7, 2024
2 parents 70b1672 + 375a154 commit 5ce79bb
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 271 deletions.

This file was deleted.

7 changes: 0 additions & 7 deletions backend/app/DomainObjects/StripeCustomerDomainObject.php

This file was deleted.

16 changes: 0 additions & 16 deletions backend/app/Models/StripeCustomer.php

This file was deleted.

6 changes: 3 additions & 3 deletions backend/app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use HiEvents\Repository\Eloquent\PromoCodeRepository;
use HiEvents\Repository\Eloquent\QuestionAnswerRepository;
use HiEvents\Repository\Eloquent\QuestionRepository;
use HiEvents\Repository\Eloquent\StripeCustomerRepository;
use HiEvents\Repository\Eloquent\ReservationRepository;
use HiEvents\Repository\Eloquent\StripePaymentsRepository;
use HiEvents\Repository\Eloquent\TaxAndFeeRepository;
use HiEvents\Repository\Eloquent\TicketPriceRepository;
Expand All @@ -46,7 +46,7 @@
use HiEvents\Repository\Interfaces\PromoCodeRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionAnswerRepositoryInterface;
use HiEvents\Repository\Interfaces\QuestionRepositoryInterface;
use HiEvents\Repository\Interfaces\StripeCustomerRepositoryInterface;
use HiEvents\Repository\Interfaces\ReservationRepositoryInterface;
use HiEvents\Repository\Interfaces\StripePaymentsRepositoryInterface;
use HiEvents\Repository\Interfaces\TaxAndFeeRepositoryInterface;
use HiEvents\Repository\Interfaces\TicketPriceRepositoryInterface;
Expand Down Expand Up @@ -83,7 +83,7 @@ class RepositoryServiceProvider extends ServiceProvider
OrganizerRepositoryInterface::class => OrganizerRepository::class,
AccountUserRepositoryInterface::class => AccountUserRepository::class,
CapacityAssignmentRepositoryInterface::class => CapacityAssignmentRepository::class,
StripeCustomerRepositoryInterface::class => StripeCustomerRepository::class,
ReservationRepositoryInterface::class => ReservationRepository::class,
];

public function register(): void
Expand Down
20 changes: 0 additions & 20 deletions backend/app/Repository/Eloquent/StripeCustomerRepository.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

use HiEvents\DataTransferObjects\BaseDTO;
use HiEvents\DomainObjects\AccountDomainObject;
use HiEvents\DomainObjects\OrderDomainObject;

class CreatePaymentIntentRequestDTO extends BaseDTO
{
public function __construct(
public readonly int $amount,
public readonly string $currencyCode,
public AccountDomainObject $account,
public OrderDomainObject $order,
)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
{
}
Expand Down Expand Up @@ -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,
],
Expand All @@ -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,
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

This file was deleted.

0 comments on commit 5ce79bb

Please sign in to comment.