إضافة تكامل Stripe
Stripe هي منصة لمعالجة المدفوعات عبر الإنترنت مصممة للأعمال التجارية على الإنترنت. يتيح تكامل Stripe لتطبيقك معالجة المعاملات والاشتراكات والبيانات المالية بشكل آمن.
خطوات التكوين
Section titled “خطوات التكوين”بعد اختيار Stripe من قائمة عمليات التكامل، ستظهر نافذة تكوين. يجب عليك تقديم بيانات الاعتماد التالية من لوحة تحكم Stripe الخاصة بك لإنشاء الاتصال:
1. المفتاح السري (Secret Key)
Section titled “1. المفتاح السري (Secret Key)”- الإدخال: أدخل المفتاح السري الخاص بك في Stripe (يبدأ عادةً بـ
sk_) في حقل Secret Key. يتيح هذا المفتاح للواجهة الخلفية مصادقة الطلبات الآمنة.
2. المفتاح القابل للنشر (Publishable Key)
Section titled “2. المفتاح القابل للنشر (Publishable Key)”- الإدخال: أدخل المفتاح القابل للنشر العام الخاص بك في Stripe (يبدأ عادةً بـ
pk_) في حقل Publishable Key. يستخدم هذا المفتاح لتنفيذ الواجهة الأمامية.
3. البيئة (Environment)
Section titled “3. البيئة (Environment)”- الإدخال: حدد سياق البيئة المناسب من القائمة المنسدلة (على سبيل المثال، Test لوضع التطوير/صندوق الحماية أو Production للمعالجة المباشرة).
إتمام الاتصال
Section titled “إتمام الاتصال”بمجرد تكوين المفاتيح والبيئة:
- تحقق من شريط الحالة (يظهر حاليًا Not Connected).
- انقر فوق الزر الأسود Add في أسفل اليمين لحفظ بيانات الاعتماد وتمكين تكامل الدفع.


مرجع واجهة برمجة تطبيقات تكامل Stripe
Section titled “مرجع واجهة برمجة تطبيقات تكامل Stripe”إدارة التكوين
Section titled “إدارة التكوين”configureStripe
Section titled “configureStripe”إنشاء تكوين Stripe جديد للمشروع والبيئة.
Mutation:
mutation ConfigureStripe ( $input: ConfigureStripeInput!) { configureStripe ( input: $input ) { id publishableKey webhookUrl }}Input:
input ConfigureStripeInput { secretKey: String! # Stripe secret key (sk_test_... or sk_live_...) publishableKey: String! # Stripe publishable key (pk_test_... or pk_live_...) environment: StripeEnvironment! # TEST or LIVE webhookSecret: String # Webhook signing secret (optional)}Response:
type ConfigureStripePayload { id: ID! # Configuration ID publishableKey: String! # Publishable key webhookUrl: String! # Generated webhook URL}Example:
{ "input": { "secretKey": "sk_test_...", "publishableKey": "pk_test_...", "environment": "TEST", "webhookSecret": "whsec_..." }}ملاحظات:
- يتم تشفير المفتاح السري باستخدام AES-256-GCM قبل التخزين
- تكوين واحد فقط لكل مجموعة مشروع/بيئة
- إرجاع خطأ إذا كان التكوين موجودًا بالفعل
updateStripeConfig
Section titled “updateStripeConfig”تحديث تكوين Stripe الحالي.
Mutation:
mutation UpdateStripeConfig ( $input: UpdateStripeConfigInput!) { updateStripeConfig ( input: $input ) { id publishableKey webhookUrl }}Input:
input UpdateStripeConfigInput { secretKey: String # Optional publishableKey: String # Optional environment: StripeEnvironment # Optional webhookSecret: String # Optional}Response:
type UpdateStripeConfigPayload { id: ID! publishableKey: String! webhookUrl: String!}ملاحظات:
- جميع الحقول اختيارية
- يتم تحديث الحقول المقدمة فقط
- يتم تشفير المفتاح السري إذا تم توفيره
إدارة العملاء
Section titled “إدارة العملاء”stripe_customer
Section titled “stripe_customer”استرداد عميل واحد بواسطة المعرف.
Query:
query stripe_customer{ stripe_customer( id: "cus_Ts..." ) { id name email phone description metadata object createdAt }}stripe_customers
Section titled “stripe_customers”سرد العملاء مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_customers ( $first: Int, $after: String, $customerId: String) { stripe_customers ( first: $first, after: $after, customerId: $customerId ) { edges { node { id name email phone description createdAt } cursor } pageInfo { hasNextPage hasPreviousPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتcustomerId: تصفية حسب معرف العميل (اختياري)
stripe_createCustomer
Section titled “stripe_createCustomer”إنشاء عميل جديد.
Mutation:
mutation stripe_createCustomer { stripe_createCustomer ( input: { name: "Customer", email: "example@archie.com", phone: "+573001230001", description: "Description Example" metadata: { data1: "Example data1", data2: "Example data2" } } ) { id name email phone description metadata object createdAt }}stripe_updateCustomer
Section titled “stripe_updateCustomer”تحديث عميل حالي.
Mutation:
mutation stripe_updateCustomer { stripe_updateCustomer( id: "cus_Ts...", input: { name: "Customer", email: "example@archie.com", phone: "+573001230001", description:"Description Example", metadata: { data1: "Example data1 updated", data2: "Example data2 updated" } } ) { id name email phone description metadata object createdAt }}ملاحظات:
- جميع الحقول اختيارية
- يتم تحديث الحقول المقدمة فقط
stripe_deleteCustomer
Section titled “stripe_deleteCustomer”حذف عميل.
Mutation:
mutation stripe_deleteCustomer { stripe_deleteCustomer ( id: "cus_Ts...")}Response:
- إرجاع
trueعند النجاح - إرجاع خطأ إذا لم يتم العثور على العميل
نوايا الدفع (Payment Intents)
Section titled “نوايا الدفع (Payment Intents)”stripe_paymentIntent
Section titled “stripe_paymentIntent”استرداد نية دفع واحدة بواسطة المعرف.
Query:
query stripe_paymentIntent { stripe_paymentIntent ( id: "pi_3Su..." ) { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt }}stripe_paymentIntents
Section titled “stripe_paymentIntents”سرد نوايا الدفع مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_paymentIntents ( $first: Int, $after: String, $customerId: String) { stripe_paymentIntents ( first: $first, after: $after, customerId: $customerId ) { edges { node { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتcustomerId: تصفية حسب معرف العميل (اختياري)
stripe_createPaymentIntent
Section titled “stripe_createPaymentIntent”إنشاء نية دفع جديدة.
Mutation:
mutation stripe_createPaymentIntent { stripe_createPaymentIntent ( input: { amount: 12.35, currency: "usd", customerId: "cus_Ts...", paymentMethodId: "pm_1Su...", automaticPaymentMethods: true } ) { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt }}ملاحظات:
- يتم إرجاع
clientSecretلتأكيد الواجهة الأمامية - استخدم
automaticPaymentMethods: trueللتكامل مع Stripe.js
stripe_updatePaymentIntent
Section titled “stripe_updatePaymentIntent”تحديث نية الدفع قبل التأكيد.
Mutation:
mutation stripe_updatePaymentIntent{ stripe_updatePaymentIntent( id: "pi_3S...", input: { amount: 36.92, currency: "usd", paymentMethodId: "pm_1Su..." metadata:{ data1: "Example data1" } } ) { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt }}ملاحظات:
- يمكن التحديث فقط قبل التأكيد
- جميع الحقول اختيارية
stripe_confirmPaymentIntent
Section titled “stripe_confirmPaymentIntent”تأكيد نية الدفع.
Mutation:
mutation stripe_confirmPaymentIntent{ stripe_confirmPaymentIntent( id: "pi_3Su..." input: { paymentMethodId: "pm_1Su...", returnUrl: "http://localhost:3000/successful-payment" } ) { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt }}ملاحظات:
- مطلوب لإكمال الدفع
- قد يتطلب مصادقة 3D Secure
- إرجاع الحالة المحدثة (succeeded, requires_action, إلخ)
stripe_cancelPaymentIntent
Section titled “stripe_cancelPaymentIntent”إلغاء نية الدفع.
Mutation:
mutation stripe_cancelPaymentIntent { stripe_cancelPaymentIntent( id: "pi_3Su..." ) { id customerId paymentMethodId currency amount status metadata object clientSecret createdAt }}ملاحظات:
- يمكن إلغاء نوايا الدفع التي لم تنجح أو لم يتم إلغاؤها فقط
- تتغير الحالة إلى “canceled”
الاشتراكات
Section titled “الاشتراكات”stripe_subscription
Section titled “stripe_subscription”استرداد اشتراك واحد بواسطة المعرف.
Query:
query stripe_subscription { stripe_subscription(id: "sub_1Su...") { id customerId status currentPeriodStart currentPeriodEnd createdAt cancelAtPeriodEnd metadata object items { data { id priceId quantity } } }}stripe_subscriptions
Section titled “stripe_subscriptions”سرد الاشتراكات مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_subscriptions ( $first: Int, $after: String, $customerId: String) { stripe_subscriptions ( first: $first, after: $after, customerId: $customerId ) { edges { node { id customerId status currentPeriodStart currentPeriodEnd createdAt cancelAtPeriodEnd metadata object items { data { id priceId quantity } } } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتcustomerId: تصفية حسب معرف العميل (اختياري)status: تصفية حسب الحالة (اختياري)
stripe_createSubscription
Section titled “stripe_createSubscription”إنشاء اشتراك جديد.
Mutation:
mutation stripe_createSubscription { stripe_createSubscription ( input: { customerId: "cus_TsQ...", items: { priceId: "price_1Su...", quantity: 1 }, metadata: { data1: "Example data1" }, trialPeriodDays: 0 } ) { id customerId status currentPeriodStart currentPeriodEnd createdAt cancelAtPeriodEnd metadata object items { data { id priceId quantity } } }}ملاحظات:
- يمكن أن يكون
paymentBehavior“default_incomplete” للاشتراكات التي تتطلب طريقة دفع - يتم تحديد فترة التجربة بالأيام
- يتم توسيع أحدث فاتورة ونية دفع تلقائيًا
stripe_updateSubscription
Section titled “stripe_updateSubscription”تحديث اشتراك حالي.
Mutation:
mutation stripe_updateSubscription { stripe_updateSubscription( id: "sub_1Sv..." input: { cancelAtPeriodEnd: false metadata: { data2: "Example data2" } } ) { id customerId status currentPeriodStart currentPeriodEnd createdAt cancelAtPeriodEnd metadata object items { data { id priceId quantity } } }}stripe_cancelSubscription
Section titled “stripe_cancelSubscription”إلغاء اشتراك.
Mutation:
mutation stripe_cancelSubscription { stripe_cancelSubscription ( cancelAtPeriodEnd: true, id: "sub_1Sv..." ) { id customerId status currentPeriodStart currentPeriodEnd createdAt cancelAtPeriodEnd metadata object items { data { id priceId quantity } } }}Parameters:
id: معرف الاشتراك (مطلوب)cancelAtPeriodEnd: إذا كان صحيحًا، يتم الإلغاء في نهاية الفترة؛ إذا كان خطأ، يتم الإلغاء فورًا (الافتراضي: خطأ)
ملاحظات:
- الإلغاء الفوري: ينتهي الاشتراك الآن
- الإلغاء في نهاية الفترة: يستمر الاشتراك حتى نهاية الفترة الحالية
المنتجات والأسعار
Section titled “المنتجات والأسعار”stripe_products
Section titled “stripe_products”سرد المنتجات مع ترقيم الصفحات.
Query:
query stripe_products ( $first: Int, $after: String) { stripe_products ( first: $first, after: $after ) { edges { node { id name description active metadata object createdAt } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}stripe_createProduct
Section titled “stripe_createProduct”إنشاء منتج جديد.
Mutation:
mutation stripe_createProduct { stripe_createProduct ( input: { name: "Product 01", description: "Description product 01", metadata: { data1: "Example data1" } } ) { id name description active metadata object createdAt }}stripe_prices
Section titled “stripe_prices”سرد الأسعار مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_prices ( $first: Int, $after: String, $productId: String) { stripe_prices ( first: $first, after: $after, productId: $productId ) { edges { node { id productId active currency unitAmount object metadata createdAt recurring { interval intervalCount } } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتproductId: تصفية حسب معرف المنتج (اختياري)
stripe_createPrice
Section titled “stripe_createPrice”إنشاء سعر جديد.
Mutation:
mutation stripe_createPrice { stripe_createPrice ( input: { productId: "prod_Tst...", unitAmount: 25.85, currency: "usd", recurring: { interval: "month", intervalCount: 1 }, metadata: { data1: "Example data1" } } ) { id productId currency unitAmount active object createdAt metadata recurring { interval intervalCount } }}ملاحظات:
- اترك
recurringللمبالغ المدفوعة لمرة واحدة - يجب أن يكون
intervalواحدًا من: “day”, “week”, “month”, “year”
الفواتير (Invoices)
Section titled “الفواتير (Invoices)”stripe_invoice
Section titled “stripe_invoice”استرداد فاتورة واحدة بواسطة المعرف.
Query:
query stripe_invoice { stripe_invoice ( id: "in_1Su..." ) { id customerId subscriptionId currency amountPaid amountDue status object metadata createdAt lineItems { data { id description currency amount quantity } } }}ملاحظات:
- يتم تعبئة معرف الاشتراك عن طريق توسيع API عند توفره
stripe_invoices
Section titled “stripe_invoices”سرد الفواتير مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_invoices ( $first: Int, $after: String, $customerId: String, $status: String) { stripe_invoices ( first: $first, after: $after, customerId: $customerId, status: $status ) { edges { node { id customerId subscriptionId currency amountPaid amountDue status object metadata createdAt lineItems { data { id description currency amount quantity } } } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتcustomerId: تصفية حسب معرف العميل (اختياري)status: تصفية حسب الحالة (اختياري)
stripe_payInvoice
Section titled “stripe_payInvoice”دفع فاتورة برمجياً.
Mutation:
mutation stripe_payInvoice { stripe_payInvoice ( id: "in_1Sv..." ) { id customerId subscriptionId currency amountPaid amountDue status object metadata createdAt lineItems { data { id description currency amount quantity } } }}ملاحظات:
- محاولات لدفع الفاتورة باستخدام طريقة الدفع الافتراضية للعميل
- إرجاع خطأ إذا فشل الدفع
- تحديث حالة الفاتورة إلى “paid” عند النجاح
المبالغ المستردة (Refunds)
Section titled “المبالغ المستردة (Refunds)”stripe_refunds
Section titled “stripe_refunds”سرد المبالغ المستردة مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_refunds ( $first: Int, $after: String, $paymentIntentId: String) { stripe_refunds ( first: $first, after: $after, paymentIntentId: $paymentIntentId ) { edges { node { id paymentIntentId reason status currency amount metadata object createdAt } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتpaymentIntentId: تصفية حسب معرف نية الدفع (اختياري)
stripe_createRefund
Section titled “stripe_createRefund”إنشاء استرداد لنية الدفع.
Mutation:
mutation stripe_createRefund { stripe_createRefund ( input: { paymentIntentId: "pi_3Sv...", amount: 200, reason: "requested_by_customer" } ) { id reason paymentIntentId status currency amount object metadata createdAt }}ملاحظات:
- اترك
amountلاسترداد المبلغ بالكامل - يمكن أن يكون
reason: “duplicate”, “fraudulent”, “requested_by_customer” - تبدأ حالة الاسترداد بـ “pending” ويتم تحديثها إلى “succeeded” أو “failed”
طرق الدفع (Payment Methods)
Section titled “طرق الدفع (Payment Methods)”stripe_paymentMethods
Section titled “stripe_paymentMethods”سرد طرق الدفع مع ترقيم الصفحات والتصفية الاختيارية.
Query:
query stripe_paymentMethods ( $first: Int, $after: String, $customerId: String) { stripe_paymentMethods( first: $first, after: $after, customerId: $customerId ) { edges { node { id customerId type object metadata createdAt card { brand expMonth expYear last4 } } cursor } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } }}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحاتcustomerId: تصفية حسب معرف العميل (اختياري)
ملاحظات:
- يتم إرجاع معلومات البطاقة الآمنة فقط (آخر 4 أرقام، العلامة التجارية، انتهاء الصلاحية)
- لا يتم كشف أرقام البطاقات الكاملة أبدًا
stripe_attachPaymentMethod
Section titled “stripe_attachPaymentMethod”إرفاق طريقة دفع بعميل.
Mutation:
mutation stripe_attachPaymentMethod { stripe_attachPaymentMethod ( id: "pm_1Sv...", input: { customerId: "cus_Ts4..." } ) { id customerId type card { brand expMonth expYear last4 } metadata object createdAt }}ملاحظات:
- يجب إنشاء طريقة الدفع أولاً (عادة عبر Stripe.js)
- يمكن استخدام طرق الدفع المرفقة للاشتراكات والمدفوعات
stripe_detachPaymentMethod
Section titled “stripe_detachPaymentMethod”فصل طريقة دفع عن عميل.
Mutation:
mutation stripe_detachPaymentMethod { stripe_detachPaymentMethod ( id: "pm_1Sv..." ) { id customerId type card { brand expYear expMonth last4 } metadata object createdAt }}ملاحظات:
- لا يمكن استخدام طرق الدفع المفصولة للمدفوعات بعد الآن
- إرجاع طريقة الدفع مع تعيين
customerIdإلى null
أحداث Webhook
Section titled “أحداث Webhook”stripe_webhookEvents
Section titled “stripe_webhookEvents”سرد أحداث webhook التي تتلقاها الخدمة.
Query:
query ListWebhookEvents ( $first: Int, $after: String) { stripe_webhookEvents ( first: $first, after: $after ) { edges { node { id type data processed createdAt } cursor } pageInfo { hasNextPage hasPreviousPage endCursor } }}Response:
type StripeWebhookEvent { id: ID! type: String! # Event type (e.g., "payment_intent.succeeded") data: String! # JSON string of event data processed: Boolean! # Whether event has been processed createdAt: Time!}Parameters:
first: عدد العناصر التي سيتم إرجاعها (الافتراضي: 10)after: مؤشر لترقيم الصفحات
ملاحظات:
- يتم تلقي الأحداث تلقائيًا عبر نقطة نهاية webhook
- يتم تخزين الأحداث بعد التحقق من التوقيع
- يحتوي الحقل
dataعلى حمولة الحدث الكاملة كسلسلة JSON
ترقيم الصفحات (Pagination)
Section titled “ترقيم الصفحات (Pagination)”تدعم جميع استعلامات القائمة ترقيم الصفحات المستند إلى المؤشر باستخدام نمط اتصال Relay.
PageInfo
Section titled “PageInfo”type PageInfo { hasNextPage: Boolean! hasPreviousPage: Boolean! startCursor: String endCursor: String}مثال على الاستخدام
Section titled “مثال على الاستخدام”query ListCustomers ( $first: Int, $after: String) { stripe_customers ( first: $first, after: $after ) { edges { node { id email } cursor } pageInfo { hasNextPage endCursor } }}تدفق ترقيم الصفحات:
- الطلب الأولي:
first: 10, after: null - استخدم
pageInfo.endCursorمن الاستجابة كـafterفي الطلب التالي - تحقق من
hasNextPageلتحديد ما إذا كانت هناك صفحات أخرى
القيم الافتراضية:
first: الافتراضي إلى 10 إذا لم يتم توفيرهafter: يبدأ من البداية إذا لم يتم توفيره
معالجة الأخطاء
Section titled “معالجة الأخطاء”تُرجع جميع العمليات أخطاء GraphQL برسائل سهلة القراءة. يتم تعيين الأخطاء من أخطاء Stripe API لتقديم ملاحظات واضحة.
سيناريوهات الخطأ الشائعة
Section titled “سيناريوهات الخطأ الشائعة”أخطاء التكوين:
400: تنسيق مفتاح Stripe غير صالح404: المشروع أو التكوين غير موجود400: التكوين موجود بالفعل
أخطاء العميل:
404: العميل غير موجود400: بيانات العميل غير صالحة
أخطاء خيار الدفع:
404: نية الدفع غير موجودة400: مبلغ أو عملة غير صالحة402: فشل الدفع (تم رفض البطاقة، رصيد غير كافٍ، إلخ)
أخطاء الاشتراك:
404: الاشتراك غير موجود400: معلمات الاشتراك غير صالحة400: لا يمكن تحديث اشتراك ملغى
رموز خطأ Stripe: يتم تعيين رموز خطأ Stripe الشائعة إلى رسائل سهلة القراءة:
card_declined: “تم رفض بطاقتك”insufficient_funds: “رصيد غير كافٍ”invalid_number: “رقم البطاقة غير صالح”expired_card: “انتهت صلاحية البطاقة”incorrect_cvc: “رمز CVC غير صحيح”
تنسيق استجابة الخطأ
Section titled “تنسيق استجابة الخطأ”{ "errors": [ { "message": "Customer not found", "extensions": { "code": "NOT_FOUND", "stripeErrorCode": "resource_missing" } } ], "data": null}أنواع البيانات
Section titled “أنواع البيانات”StripeEnvironment
Section titled “StripeEnvironment”enum StripeEnvironment { TEST # Test mode LIVE # Live/production mode}Scalar Map
Section titled “Scalar Map”يمثل النوع القياسي Map تعيين مفتاح بقيمة حيث:
- المفاتيح عبارة عن سلاسل
- يمكن أن تكون القيم سلاسل أو أرقامًا أو منطقية أو خرائط متداخلة
- تستخدم لحقول البيانات الوصفية
مثال:
{ "metadata": { "order_id": "12345", "user_id": "67890", "premium": true }}Scalar Time
Section titled “Scalar Time”يمثل النوع القياسي Time الطوابع الزمنية بتنسيق ISO 8601.
مثال: "2025-11-16T00:28:48.081Z"