mastercard mdes customer service net45 tutorial
1.0.0
MasterCard提供了客戶庫與其服務集成,但是.NET軟件包不支持.NET Framework 4.5,其支持於2016年結束:
本教程解釋瞭如何通過使用OPARAPI生成器生成API客戶端庫,並使用.NET 4.5版本的OAuth1 Signer lib生成API客戶庫,從而從.NET 4.5應用程序使用MasterCard MDES客戶服務。
可以使用以下命令生成MDE客戶服務的.NET 4.5客戶庫:
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 Elements,示例: < 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默認情況下,當我們生成的代碼期望使用JSON時,MDES客戶服務正在接受和返回XML有效載荷。
要指示我們會說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 。