PaymentCallback.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Webkul\BagistoApi\Models;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\GraphQl\Mutation;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Webkul\BagistoApi\Dto\PaymentCallbackInput;
  8. use Webkul\BagistoApi\State\PaymentCallbackProcessor;
  9. /**
  10. * paymentCallbackCreate — Frontend invokes this after the gateway
  11. * redirect lands back on the storefront. `status` drives the branch:
  12. *
  13. * - success: captures the gateway order (PayPal) and, for express
  14. * flows, fills the order's shipping/billing addresses with the data
  15. * forwarded from the gateway.
  16. * - cancel / failure: leaves the order in PENDING so the user can
  17. * decide to either retry (paymentReplay) or cancel (cancelOrder).
  18. */
  19. #[ApiResource(
  20. routePrefix: '/api/shop',
  21. shortName: 'PaymentCallback',
  22. operations: [],
  23. graphQlOperations: [
  24. new Mutation(
  25. name: 'create',
  26. input: PaymentCallbackInput::class,
  27. output: self::class,
  28. processor: PaymentCallbackProcessor::class,
  29. denormalizationContext: [
  30. 'allow_extra_attributes' => true,
  31. 'groups' => ['mutation'],
  32. ],
  33. normalizationContext: [
  34. 'groups' => ['mutation'],
  35. ],
  36. description: 'Handle gateway return (success/cancel/failure). Captures the gateway order on success and fills express addresses if forwarded.',
  37. ),
  38. ]
  39. )]
  40. class PaymentCallback
  41. {
  42. #[ApiProperty(identifier: true, readable: true, writable: false)]
  43. #[Groups(['mutation'])]
  44. public ?int $id = null;
  45. #[ApiProperty(readable: true, writable: false)]
  46. #[Groups(['mutation'])]
  47. public bool $success = false;
  48. #[ApiProperty(readable: true, writable: false)]
  49. #[Groups(['mutation'])]
  50. public string $message = '';
  51. #[ApiProperty(readable: true, writable: false)]
  52. #[Groups(['mutation'])]
  53. public ?string $orderId = null;
  54. #[ApiProperty(readable: true, writable: false)]
  55. #[Groups(['mutation'])]
  56. public ?string $status = null;
  57. #[ApiProperty(readable: true, writable: false)]
  58. #[Groups(['mutation'])]
  59. public ?string $orderStatus = null;
  60. #[ApiProperty(readable: true, writable: false)]
  61. #[Groups(['mutation'])]
  62. public ?string $gatewayStatus = null;
  63. }