Data Transfer Objects (DTOs)
All DTOs implement Arrayable and JsonSerializable.
CartItem
Eamirgh\SnappPay\DTOs\CartItem
Represents an individual order item line:
id:int|stringname:stringcount:intamount:int(unit price in IRR)category:stringcommissionType:int(default100)
Methods
CartItem::make(...): Factory method.CartItem::adapt(mixed $item): CartItem: Polymorphic adapter that convertsSnappPayCartItemInterfaceinstances, raw arrays, or existingCartItemobjects.CartItem::fromContract(SnappPayCartItemInterface $item): CartItem: Converts an interface model.CartItem::fromArray(array $data): Deserialization.totalAmount(): int: Returnscount * amount.toArray(): array: Serializes to SnappPay JSON payload format.
Cart
Eamirgh\SnappPay\DTOs\Cart
Represents a cart container holding items:
cartId:int|stringcartItems:array<CartItem>isShipmentIncluded:bool(defaulttrue)isTaxIncluded:bool(defaulttrue)shippingAmount:int(default0)taxAmount:int(default0)totalAmount:?int(auto-calculated if null)
Methods
Cart::make(...): Factory method.Cart::adapt(mixed $cart): Cart: Polymorphic adapter that convertsSnappPayCartInterfaceinstances, raw arrays, or existingCartobjects.Cart::fromContract(SnappPayCartInterface $cart): Cart: Converts a cart model implementingSnappPayCartInterface.Cart::fromArray(array $data): Deserialization.addItem(CartItem|SnappPayCartItemInterface $item): self: Appends an item.calculateTotal(): int: Computes total based on SnappPay arithmetic rules.getTotalAmount(): int: Returns pre-set total or computes dynamically.
Calculation Formula
[count] × [amount] + [shippingAmount if not included] + [taxAmount if not included]PaymentTokenRequest
Eamirgh\SnappPay\DTOs\PaymentTokenRequest
The complete request payload for initiating payment:
amount:int(Net order amount)cartList:array<Cart>mobile:stringreturnURL:stringtransactionId:stringdiscountAmount:intexternalSourceAmount:intforcedPaymentMethodTypes:?array
Validation
- Validates
transactionIdrequirements (5-10 digits, or >10 chars with letter). - Validates that
sum(carts) - discountAmount - externalSourceAmount === amount.
CallbackPayload
Eamirgh\SnappPay\DTOs\CallbackPayload
Represents inbound data from SnappPay's POST callback:
transactionId:stringstate:CallbackState(OKorFAILED)amount:intisOk(): boolisFailed(): bool
StatusResult
Eamirgh\SnappPay\DTOs\StatusResult
Represents payment status inquiry response:
transactionId:stringstatus:PaymentStatus(SETTLE,CANCEL,VERIFY,PENDING,REVERT)amount:intisSettled(): boolisVerified(): boolisPending(): boolisCancelled(): boolisReverted(): bool
UpdateOrderRequest
Eamirgh\SnappPay\DTOs\UpdateOrderRequest
Payload for updating orders post-settlement:
paymentToken:stringamount:int(New total, strictly less than original)cartList:array<Cart>(Excludes removed items)discountAmount:intexternalSourceAmount:int