inital commit
This commit is contained in:
45
payment/services.py
Normal file
45
payment/services.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import uuid
|
||||
from decimal import Decimal
|
||||
|
||||
from .models import PaymentRecord
|
||||
|
||||
|
||||
def _generate_id(prefix):
|
||||
return f"{prefix}_{uuid.uuid4().hex[:24]}"
|
||||
|
||||
|
||||
def create_mock_payment_intent(*, booking, amount: Decimal, currency: str = "usd"):
|
||||
payment = PaymentRecord.objects.create(
|
||||
booking=booking,
|
||||
stripe_payment_intent_id=_generate_id("pi_mock"),
|
||||
amount=amount,
|
||||
currency=currency,
|
||||
status=PaymentRecord.Status.REQUIRES_PAYMENT,
|
||||
)
|
||||
client_secret = _generate_id("pi_secret_mock")
|
||||
return payment, client_secret
|
||||
|
||||
|
||||
def mark_payment_processing(payment):
|
||||
payment.status = PaymentRecord.Status.PROCESSING
|
||||
payment.save(update_fields=["status", "updated_at"])
|
||||
return payment
|
||||
|
||||
|
||||
def mark_payment_succeeded(payment):
|
||||
payment.status = PaymentRecord.Status.SUCCEEDED
|
||||
payment.stripe_charge_id = _generate_id("ch_mock")
|
||||
payment.save(update_fields=["status", "stripe_charge_id", "updated_at"])
|
||||
return payment
|
||||
|
||||
|
||||
def mark_payment_failed(payment):
|
||||
payment.status = PaymentRecord.Status.FAILED
|
||||
payment.save(update_fields=["status", "updated_at"])
|
||||
return payment
|
||||
|
||||
|
||||
def mark_payment_refunded(payment):
|
||||
payment.status = PaymentRecord.Status.REFUNDED
|
||||
payment.save(update_fields=["status", "updated_at"])
|
||||
return payment
|
||||
Reference in New Issue
Block a user