mastercard mdes customer service net45 tutorial
1.0.0
يوفر MasterCard مكتبات العملاء للتكامل مع خدماتها ، لكن حزم .NET لا تدعم .NET Framework 4.5 ، التي انتهى دعمها في عام 2016:
يشرح هذا البرنامج التعليمي كيفية استهلاك خدمة عملاء MasterCard MDES من تطبيق .NET 4.5 عن طريق إنشاء مكتبة عميل API مع مولد OpenAPI وتوقيع طلبات HTTP باستخدام إصدار .NET 4.5 من Signer LIB.
يمكن إنشاء مكتبة عميل .NET 4.5 لخدمة عملاء MDES باستخدام الأمر التالي:
java -jar openapi-generator-cli.jar generate -i mdes-customer-service-2.0.4.yaml -g csharp -c config.json -o mdes-customer-service-net45-tutorialconfig.json:
{
"targetFramework" : " v4.5 " ,
"packageName" : " YourApp.MdesCustomerClient "
}انظر أيضًا: Openapi Generator (قابل للتنفيذ)
Condition="Exists('....packages')" في عناصر HintPath ، مثال: < Reference Include = " RestSharp " >
< HintPath >....packagesRestSharp.105.1.0libnet45RestSharp.dll</ HintPath >
</ Reference >YourApp.Console :YourApp.MdesCustomerClientMastercard.Developer.OAuth1Signer.Core.dll (.NET 4.5 الإصدار)Mastercard.Developer.OAuth1Signer.RestSharp.dll (.NET 4.5 الإصدار)RestSharp.dllApiClient لاستخدام JSONبشكل افتراضي ، تقوم خدمة عملاء MDES بقبول وإعادة حمولة XML عندما تتوقع رمزنا الذي تم إنشاؤه استخدام JSON.
للإشارة إلى الخدمة التي نتحدث عنها JSON ، قم بإنشاء فصل جديد في مشروع YourApp.MdesCustomerClient الذي يحدد الطريقة الجزئية InterceptRequest بالطريقة التالية:
using RestSharp ;
namespace YourApp . MdesCustomerClient . Client
{
/// <summary>
/// Extends the generated ApiClient class.
/// </summary>
public partial class ApiClient
{
/// <summary>
/// Adds "Format=JSON" to the RestSharp request so that the service accepts and returns JSON instead of XML.
/// </summary>
partial void InterceptRequest ( IRestRequest request ) => request . AddQueryParameter ( "Format" , "JSON" ) ;
}
} class Program
{
static void Main ( string [ ] args )
{
// The request was aborted: Could not create SSL/TLS secure channel
ServicePointManager . Expect100Continue = true ;
ServicePointManager . SecurityProtocol = SecurityProtocolType . Tls12 ;
var consumerKey = "<insert consumer key>" ;
var signingKey = SecurityUtils . LoadPrivateKey ( "<insert PKCS#12 key file path>" , "<insert key alias>" , "<insert key password>" ) ; // Pass X509KeyStoragFlags here
var config = Configuration . Default ;
config . BasePath = "https://sandbox.api.mastercard.com/mdes/csapi/v2" ;
config . ApiClient . RestClient . Authenticator = new RestSharpOAuth1Authenticator ( consumerKey , signingKey , new Uri ( config . BasePath ) ) ;
var searchApi = new SearchApi ( config ) ;
var auditInfo = new AuditInfo ( "A1435477" , "John Smith" , "Any Bank" , "5555551234" ) ;
var tokenUniqueReference = "DWSPMC00000000010906a349d9ca4eb1a4d53e3c90a11d9c" ;
var searchRequest = new SearchRequest ( null , tokenUniqueReference , null , null , null , null , null , null , auditInfo ) ;
var response = searchApi . SearchPost ( new SearchRequestSchema ( searchRequest ) ) ;
System . Console . WriteLine ( response . SearchResponse . Accounts . Account [ 0 ] . Tokens . Token [ 0 ] ) ;
System . Console . ReadLine ( ) ;
}
}consumerKey الخاص ، pkcs12KeyFilePath ، signingKeyAlias ، signingKeyAlias و keyStorageFlags .