mastercard mdes customer service net45 tutorial
1.0.0
MasterCard ให้บริการไลบรารีลูกค้าสำหรับการรวมเข้ากับบริการ แต่แพ็คเกจ. NET ไม่รองรับ. NET Framework 4.5 ซึ่งการสนับสนุนสิ้นสุดลงในปี 2559:
บทช่วยสอนนี้อธิบายวิธีการใช้บริการลูกค้า MasterCard MDES จากแอพ. NET 4.5 โดยการสร้างไลบรารีไคลเอนต์ API ด้วยเครื่องกำเนิด OpenAPI และการลงนามคำขอ HTTP โดยใช้. NET 4.5 รุ่นของผู้ลงนาม OAUTH1 LIB
A .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 (Executable)
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 Payloads เมื่อรหัสที่สร้างขึ้นของเราคาดว่าจะใช้ 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