Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/app/DomainObjects/Enums/PaymentProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ enum PaymentProviders: string
use BaseEnum;

case STRIPE = 'STRIPE';
case RAZORPAY = 'RAZORPAY';
case OFFLINE = 'OFFLINE';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php

namespace HiEvents\DomainObjects\Generated;

/**
* THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
* @package HiEvents\DomainObjects\Generated
*/
abstract class RazorpayOrderDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
{
final public const SINGULAR_NAME = 'razorpay_order';
final public const PLURAL_NAME = 'razorpay_orders';
final public const ID = 'id';
final public const ORDER_ID = 'order_id';
final public const RAZORPAY_ORDER_ID = 'razorpay_order_id';
final public const RAZORPAY_PAYMENT_ID = 'razorpay_payment_id';
final public const RAZORPAY_SIGNATURE = 'razorpay_signature';
final public const AMOUNT = 'amount';
final public const CURRENCY = 'currency';
final public const RECEIPT = 'receipt';
final public const PAYMENT_STATUS = 'payment_status';
final public const CREATED_AT = 'created_at';
final public const UPDATED_AT = 'updated_at';

protected int $id;
protected int $order_id;
protected string $razorpay_order_id;
protected ?string $razorpay_payment_id = null;
protected ?string $razorpay_signature = null;
protected int $amount;
protected string $currency;
protected ?string $receipt = null;
protected string $payment_status = 'created';
protected ?string $created_at = null;
protected ?string $updated_at = null;

public function toArray(): array
{
return [
'id' => $this->id ?? null,
'order_id' => $this->order_id ?? null,
'razorpay_order_id' => $this->razorpay_order_id ?? null,
'razorpay_payment_id' => $this->razorpay_payment_id ?? null,
'razorpay_signature' => $this->razorpay_signature ?? null,
'amount' => $this->amount ?? null,
'currency' => $this->currency ?? null,
'receipt' => $this->receipt ?? null,
'payment_status' => $this->payment_status ?? null,
'created_at' => $this->created_at ?? null,
'updated_at' => $this->updated_at ?? null,
];
}

public function setId(int $id): self
{
$this->id = $id;
return $this;
}

public function getId(): int
{
return $this->id;
}

public function setOrderId(int $order_id): self
{
$this->order_id = $order_id;
return $this;
}

public function getOrderId(): int
{
return $this->order_id;
}

public function setRazorpayOrderId(string $razorpay_order_id): self
{
$this->razorpay_order_id = $razorpay_order_id;
return $this;
}

public function getRazorpayOrderId(): string
{
return $this->razorpay_order_id;
}

public function setRazorpayPaymentId(?string $razorpay_payment_id): self
{
$this->razorpay_payment_id = $razorpay_payment_id;
return $this;
}

public function getRazorpayPaymentId(): ?string
{
return $this->razorpay_payment_id;
}

public function setRazorpaySignature(?string $razorpay_signature): self
{
$this->razorpay_signature = $razorpay_signature;
return $this;
}

public function getRazorpaySignature(): ?string
{
return $this->razorpay_signature;
}

public function setAmount(int $amount): self
{
$this->amount = $amount;
return $this;
}

public function getAmount(): int
{
return $this->amount;
}

public function setCurrency(string $currency): self
{
$this->currency = $currency;
return $this;
}

public function getCurrency(): string
{
return $this->currency;
}

public function setReceipt(?string $receipt): self
{
$this->receipt = $receipt;
return $this;
}

public function getReceipt(): ?string
{
return $this->receipt;
}

public function setPaymentStatus(string $payment_status): self
{
$this->payment_status = $payment_status;
return $this;
}

public function getPaymentStatus(): string
{
return $this->payment_status;
}

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;
}
}
25 changes: 24 additions & 1 deletion backend/app/DomainObjects/OrderDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class OrderDomainObject extends Generated\OrderDomainObjectAbstract implements I
public ?Collection $attendees = null;

public ?StripePaymentDomainObject $stripePayment = null;

public ?RazorpayOrderDomainObject $razorpayOrder = null;

/** @var Collection<QuestionAndAnswerViewDomainObject>|null */
public ?Collection $questionAndAnswerViews = null;
Expand Down Expand Up @@ -180,6 +182,12 @@ public function setStripePayment(?StripePaymentDomainObject $stripePayment): Ord
$this->stripePayment = $stripePayment;
return $this;
}

public function setRazorpayOrder(?RazorpayOrderDomainObject $razorpayOrder): OrderDomainObject
{
$this->razorpayOrder = $razorpayOrder;
return $this;
}

public function isPartiallyRefunded(): bool
{
Expand Down Expand Up @@ -220,6 +228,11 @@ public function getStripePayment(): ?StripePaymentDomainObject
{
return $this->stripePayment;
}

public function getRazorpayOrder(): ?RazorpayOrderDomainObject
{
return $this->razorpayOrder;
}

public function isFreeOrder(): bool
{
Expand Down Expand Up @@ -286,4 +299,14 @@ public function isRefundable(): bool
&& $this->getPaymentProvider() === PaymentProviders::STRIPE->name
&& $this->getRefundStatus() !== OrderRefundStatus::REFUNDED->name;
}
}

public function isRazorpayOrder(): bool
{
return $this->getPaymentProvider() === PaymentProviders::RAZORPAY->name;
}

public function hasRazorpayOrder(): bool
{
return $this->razorpayOrder !== null;
}
}
25 changes: 25 additions & 0 deletions backend/app/DomainObjects/RazorpayOrderDomainObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace HiEvents\DomainObjects;

use HiEvents\DomainObjects\Generated\RazorpayOrderDomainObjectAbstract;

class RazorpayOrderDomainObject extends RazorpayOrderDomainObjectAbstract
{
// Additional methods or overrides can be added here

public function isPaid(): bool
{
return in_array($this->payment_status, ['captured', 'paid']);
}

public function isFailed(): bool
{
return $this->payment_status === 'failed';
}

public function isPending(): bool
{
return $this->payment_status === 'created';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace HiEvents\Exceptions\Razorpay;

class CreateOrderFailedException extends RazorpayException
{
protected $code = 422;
}
13 changes: 13 additions & 0 deletions backend/app/Exceptions/Razorpay/InvalidSignatureException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace HiEvents\Exceptions\Razorpay;

class InvalidSignatureException extends RazorpayException
{
protected $code = 400;

public function __construct(string $message = 'Invalid payment signature')
{
parent::__construct($message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace HiEvents\Exceptions\Razorpay;

class PaymentVerificationFailedException extends RazorpayException
{
protected $code = 422;
}
10 changes: 10 additions & 0 deletions backend/app/Exceptions/Razorpay/RazorpayException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HiEvents\Exceptions\Razorpay;

use Exception;

class RazorpayException extends Exception
{
protected $code = 500;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace HiEvents\Http\Actions\Common\Webhooks;

use HiEvents\Http\Actions\BaseAction;
use HiEvents\Http\ResponseCodes;
use HiEvents\Services\Application\Handlers\Order\Payment\Razorpay\RazorpayWebhookHandler;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class RazorpayIncomingWebhookAction extends BaseAction
{
public function __invoke(Request $request): Response
{
$payload = $request->getContent();
$signature = $request->header('X-Razorpay-Signature');

dispatch(static function (RazorpayWebhookHandler $handler) use ($payload, $signature) {
$handler->handle($payload, $signature);
})->catch(function (\Throwable $exception) use ($payload) {
logger()->error(__('Failed to handle incoming Razorpay webhook'), [
'exception' => $exception,
'payload' => $payload,
]);
});

return $this->noContentResponse();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace HiEvents\Http\Actions\Orders\Payment\Razorpay;

use HiEvents\Exceptions\Razorpay\CreateOrderFailedException;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Services\Application\Handlers\Order\Payment\Razorpay\CreateRazorpayOrderHandler;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class CreateRazorpayOrderActionPublic extends BaseAction
{
public function __construct(
private readonly CreateRazorpayOrderHandler $createRazorpayOrderHandler,
)
{
}

public function __invoke(int $eventId, string $orderShortId): JsonResponse
{
try {
$razorpayOrder = $this->createRazorpayOrderHandler->handle($orderShortId);
} catch (CreateOrderFailedException $e) {
return $this->errorResponse($e->getMessage(), Response::HTTP_UNPROCESSABLE_ENTITY);
}

return $this->jsonResponse([
'razorpay_order_id' => $razorpayOrder->id,
'key_id' => $razorpayOrder->keyId,
'amount' => $razorpayOrder->amount,
'currency' => $razorpayOrder->currency,
]);
}
}
Loading