orderCreate
نظرة عامة
أنهِ عملية الدفع باستدعاء createOrder مع CreateOrderInput. يحدث هذا عادة بعد أن يقدم العميل تفاصيل الشحن/الدفع وتكون السلة جاهزة للتحويل إلى طلب.
- النوع: GraphQL Mutation
- Endpoint: https://subdomain.com
- المصادقة:
Authorization: Bearer <TOKEN>
Mutation
mutation CreateOrder($input: CreateOrderInput!) {
createOrder(input: $input) {
data {
_id
status { _id code title }
type
salesLead {
_id
firstName
lastName
country
city
district
street
phone1
phone2
}
currency { _id title currencyCode currencySymbol }
freeze
taxAmount
totalPriceWithTax
totalPrice
totalCompareAtPrice
priceWithShipping
shippingPrice
handel
paymentMethod {
_id
key
descreption
installed
deleted
schema
createdAt
updatedAt
icon
iconUrl
needConfig
methods
name
instructions
id
}
shippingAddress {
_id
country {
_id
name
image { image imageUrl }
code
continent
capital
active
deleted
phonekey
}
city {
_id
name
description
active
deleted
country {
_id
name
image { image imageUrl }
code
continent
capital
active
deleted
phonekey
}
createdAt
}
neighborhood
zipCode
description
account
device
deleted
createdAt
updatedAt
}
customerName
isPaid
isFastOrder
createdAt
account {
_id
fullname
phone
type
verified
blocked
status
avatar
avatarUrl
deleted
devices
createdAt
updatedAt
}
items {
_id
orderId
productId
variantId
productData { title slug app images price }
variantData {
price
compareAtPrice
options {
_id
option { _id name type product }
label
sortOrder
}
}
quantity
price
compareAtPrice
totalPrice
totalCompareAtPrice
totalSavings
}
}
message
success
redirectUrl
}
}
المتغيرات
عدّل البيانات حسب تدفقك. مثال باستخدام حقول مشابهة لمقتطفك:
{
"input": {
"cartId": "<CART_ID>",
"code": "<COUPON_CODE>",
"encryptionKey": "<ENCRYPTION_KEY>",
"paymentMethod": "<PAYMENT_METHOD_KEY>",
"shippingAddressId": "<ADDRESS_ID>",
"token": "<CHECKOUT_TOKEN>",
"COD": false,
"leadData": {
"firstName": "محمد",
"lastName": "أحمد",
"country": "SA",
"city": "الرياض",
"district": "العليا",
"street": "طريق الملك فهد",
"phone1": "+966500000000",
"phone2": null
}
}
}
أمثلة
- cURL
- JavaScript (fetch)
curl -X POST \
https://subdomain.com\
-H "Content-Type": "application/json" \
-H "Authorization: Bearer <TOKEN>" \
--data-binary @- << 'EOF'
{
"query": "mutation CreateOrder($input: CreateOrderInput!) { createOrder(input: $input) { success message redirectUrl data { _id handel totalPrice } } }",
"variables": {
"input": {
"cartId": "<CART_ID>",
"paymentMethodId": "<PAYMENT_METHOD_ID>",
"shippingAddress": {
"countryId": "<COUNTRY_ID>",
"cityId": "<CITY_ID>",
"street": "Main St"
}
}
}
}
EOF
const res = await fetch('https://subdomain.com', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token,
},
body: JSON.stringify({
query: `
mutation CreateOrder($input: CreateOrderInput!) {
createOrder(input: $input) {
success
message
redirectUrl
data { _id handel totalPrice }
}
}
`,
variables: {
input: {
cartId: '<CART_ID>',
paymentMethodId: '<PAYMENT_METHOD_ID>',
shippingAddress: {
countryId: '<COUNTRY_ID>',
cityId: '<CITY_ID>',
street: 'Main St',
},
},
},
}),
});
const json = await res.json();
ملاحظات
- يُعيد الـ mutation
redirectUrlلتدفقات الدفع المستضافة - وجّه المتسوق إلى هناك عند توفره. - تأكد من أن السلة أو الجلسة المشار إليها في
CreateOrderInputصالحة ولم يتم تحويلها بعد. - استخدم
success/messageلإظهار أخطاء التحقق (العنوان المفقود، فشل الدفع، إلخ).