cartBuyNow
نظرة عامة
buyNow هو mutation مريح لإضافة منتج/متغير واحد إلى سلة مؤقتة والحصول فوراً على رابط الدفع/معلومات التشفير لتدفقات الدفع السريع.
- النوع: GraphQL Mutation
- Endpoint: https://appssubdomain.com
- المصادقة:
Authorization: Bearer <TOKEN>(إذا لزم الأمر)
Mutation
mutation BuyNow($data: AddToCartInput!) {
buyNow(data: $data) {
data {
_id
app
coupon
kind
couponApplied
couponDiscount
account {
_id
app
verified
blocked
orderCount
lastSeen
createdAt
updatedAt
}
items {
productId
_id
variantId
productData { title slug image { _id fileUrl } price }
variantData {
price
compareAtPrice
options {
_id
option { _id name type product }
label
sortOrder
}
}
quantity
price
compareAtPrice
totalPrice
totalCompareAtPrice
totalSavings
}
deviceId
sessionId
status
totalQuantity
totalPrice
totalCompareAtPrice
totalSavings
isFastOrder
createdAt
updatedAt
url
encryptionKey
}
success
message
url
encryptionKey
}
}
المتغيرات
قدم أي حقول مطلوبة من مخطط AddToCartInput الخاص بك (المنتج/المتغير، الكمية، الخيارات، معلومات الجلسة):
{
"data": {
"productId": "<PRODUCT_ID>",
"variantId": "<VARIANT_ID>",
"quantity": 1,
"sessionId": "<SESSION_ID>",
"options": [
OPTIONS_IDS
]
}
}
أمثلة
- cURL
- JavaScript (fetch)
curl -X POST \
https://appssubdomain.com\
-H "Content-Type": "application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "mutation BuyNow($data: AddToCartInput!) { buyNow(data: $data) { success message url encryptionKey data { _id totalPrice } } }",
"variables": {
"data": {
"productId": "<PRODUCT_ID>",
"variantId": "<VARIANT_ID>",
"quantity": 1,
"sessionId": "<SESSION_ID>"
}
}
}
EOF
const res = await fetch('https://appssubdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
mutation BuyNow($data: AddToCartInput!) {
buyNow(data: $data) {
success
message
url
encryptionKey
data { _id totalPrice }
}
}
`,
variables: {
data: {
productId: '<PRODUCT_ID>',
variantId: '<VARIANT_ID>',
quantity: 1,
sessionId: '<SESSION_ID>',
},
},
}),
});
const json = await res.json();
ملاحظات
- تأكد من أن المتسوق لديه السياق المطلوب (الجلسة/العملة) قبل استدعاء
buyNow. - استخدم
url/encryptionKeyالمُعادين للتوجيه مباشرة إلى صفحة الدفع أو التأكيد. - شكل البيانات يعتمد على
AddToCartInputالخاص بك؛ أضف معلومات الجهاز أو الخيارات المخصصة حسب الحاجة.