A MasterCard fornece bibliotecas clientes para integrar seus serviços, mas os pacotes .NET não suportam o .NET Framework 4.5, cujo apoio terminou em 2016:
Este tutorial explica como consumir o atendimento ao cliente da MasterCard MDES a partir de um aplicativo .NET 4.5, gerando uma biblioteca de clientes da API com o gerador OpenAPI e assinando solicitações HTTP usando uma versão .NET 4.5 do Signer OAuth1 Lib.
Uma biblioteca de clientes .NET 4.5 para o atendimento ao cliente do MDES pode ser gerada usando o seguinte comando:
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 "
}Veja também: gerador OpenAPI (executável)
Condition="Exists('....packages')" em elementos HintPath , exemplo: < Reference Include = " RestSharp " >
< HintPath >....packagesRestSharp.105.1.0libnet45RestSharp.dll</ HintPath >
</ Reference >YourApp.Console :YourApp.MdesCustomerClientMastercard.Developer.OAuth1Signer.Core.dll (versão .NET 4.5)Mastercard.Developer.OAuth1Signer.RestSharp.dll (versão .NET 4.5)RestSharp.dllApiClient para usar o JSONPor padrão, o Atendimento ao Cliente do MDES está aceitando e retornando cargas úteis XML quando nosso código gerado espera que o JSON seja usado.
Para indicar o serviço, falamos JSON, crie uma nova classe no projeto YourApp.MdesCustomerClient Definindo o método parcial InterceptRequest da seguinte maneira:
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 e keyStorageFlags .