|
26 | 26 | class StartPayResult: |
27 | 27 | url: str |
28 | 28 | payment: Payment |
| 29 | + authority: str |
29 | 30 |
|
30 | 31 |
|
31 | 32 | # ---- Helpers ---- |
@@ -198,7 +199,7 @@ def initiate_payment_for_target( |
198 | 199 | metadata={"fee_type": d.get("fee_type"), "fee": d.get("fee"), **(extra_metadata or {})}, |
199 | 200 | ) |
200 | 201 | startpay_url = f"https://payment.zarinpal.com/pg/StartPay/{authority}" |
201 | | - return StartPayResult(url=startpay_url, payment=pay) |
| 202 | + return StartPayResult(url=startpay_url, payment=pay, authority=authority) |
202 | 203 |
|
203 | 204 |
|
204 | 205 | @transaction.atomic |
@@ -275,3 +276,27 @@ def verify_by_authority(*, user: User, authority: str) -> Payment: |
275 | 276 | pass |
276 | 277 |
|
277 | 278 | return p |
| 279 | + |
| 280 | +def startpay(authority: str) -> str: |
| 281 | + current_payment = Payment.objects.filter(authority=authority).last() |
| 282 | + if not current_payment: |
| 283 | + raise CustomAPIException( |
| 284 | + code=EC.PAY_NOT_FOUND_FOR_USER, |
| 285 | + message="Payment not found for this user/authority", |
| 286 | + status_code=404) |
| 287 | + try: |
| 288 | + new_payment = initiate_payment_for_target( |
| 289 | + user=current_payment.user, |
| 290 | + target_type=current_payment.target_type, |
| 291 | + target_id=current_payment.target_id, |
| 292 | + amount=current_payment.amount, |
| 293 | + description=current_payment.description, |
| 294 | + ) |
| 295 | + except Exception as e: |
| 296 | + raise CustomAPIException( |
| 297 | + message=f"Failed to initiate payment: {e}", |
| 298 | + code=EC.COMP_PAYMENT_INIT_FAILED, |
| 299 | + status_code=409 |
| 300 | + ) |
| 301 | + return new_payment.url |
| 302 | + |
0 commit comments