mastercard mdes customer service net45 tutorial
1.0.0
MasterCardは、サービスと統合するためのクライアントライブラリを提供しますが、.NETパッケージは.NETフレームワーク4.5をサポートしていません。
このチュートリアルでは、OpenAPIジェネレーターを使用してAPIクライアントライブラリを生成し、OAUTH1署名者LIBの.NET 4.5バージョンを使用してHTTP要求に署名することにより、.NET 4.5アプリからMasterCard MDESカスタマーサービスを消費する方法について説明します。
.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ジェネレーター(実行可能ファイル)
HintPath Condition="Exists('....packages')"を削除してプロジェクトファイル(.csproj)を修正します。 < 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を拡張しますデフォルトでは、MDESカスタマーサービスは、生成されたコードがJSONが使用されることを期待している場合、XMLペイロードを受け入れて返送しています。
私たちがJSON InterceptRequest話すサービスを示すために、 YourApp.MdesCustomerClientプロジェクトで新しいクラスを作成します。
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を使用してください。