Skip to content

monnster/yandex-money-sdk-net

 
 

Repository files navigation

.NET Yandex.Money API SDK

Overview

The library allows you to make payments from bank cards and Yandex.Money wallets using Yandex.Money API. Yandex.Money API documentation: English, Russian.

See some samples here.

Requirements

The library requires .NET 4.5 or later.

Getting started

Installation

Recommended way to use the library in your own project is install it as Nuget package.

App Registration

To be able to use the library you should register your application and get your unique client id. To register an application please follow the steps described on this page (also available in Russian).

Samples

Samples.

Payments from the Yandex.Money wallet

To make payments from Yandex.Money wallet you have to:

  1. Obtain OAuth2 authorization(ru) to make payment from user using web browser. Note: clientId, redirectUri, clientSecret are constants that you get on app registration.

    var p = new AuthorizationRequestParams {
        ClientId = ClientId,
        RedirectUri = RedirectUri,
        Scope = Scopes.Compose(new[] {
            Scopes.AccountInfo, Scopes.OperationHistory, Scopes.OperationDetails, Scopes.PaymentP2P()
        })
    };
    
    var dmhp = new DefaultMobileHostsProvider();
    
    // navigate user OAuth2 permission page at our side
    WebBrowser.Navigate(dmhp.AuthorizationdUri, p.PostBytes(), ...);
  2. The user enters his login and password, reviews the list of requested permissions, and either approves or rejects the authorization request. The application receives an Authorization Response in the form of an HTTP Redirect with either a temporary authorization code or an error code.

  3. On success, application should immediately exchange temporary authorization_code to permanent access_token:

    var tr = new TokenRequest<TokenResult>(defaultHttpPostClient, new JsonSerializer<TokenResult>())
    {
        Code = "Temporary token",
        ClientId = "Your Client Id",
        RedirectUri = "Uri to inform about status"
        ClientSecret = "Your Client Secret" // not required
    };
    
    TokenResult token = await tr.Perform();
    
    authenticator.Token = token.Token;
  4. Next, you able to make payments(ru), for example transfers to another user:

    var p2P = new P2PRequestPaymentParams {
        AmountDue = "Amount to transfer", To = "User login, email or phone"
    };
    
    var rpr = new RequestPaymentRequest<RequestPaymentResult>(defaultHttpPostClient, new JsonSerializer<RequestPaymentResult>()) {
        PaymentParams = p2P.GetParams()
    };
    
    var requestPaymentResult = await rpr.Perform();
    
    if(requestPaymentResult.Status == ResponseStatus.Success) {
        var ppr = new ProcessPaymentRequest<ProcessPaymentResult>(defaultHttpPostClient, new JsonSerializer<ProcessPaymentResult>()) {
            RequestId = requestPaymentResult.RequestID,
            MoneySource = "..."
        };
    
        var processPaymentResult = await ppr.Perform();
    
        if(processPaymentResult.Status == ResponseStatus.Success) {
            // success
        }
    }

Payments from bank cards without authorization

To make payments from bank cards(ru) you have to:

  1. Registering an instance(ru) of the application. instance_id must be obtained only once and stored within application.

    var instanceIdRequest = new InstanceIdRequest < InstanceIdResult > (defaultHttpPostClient, new JsonSerializer < InstanceIdResult > ()) {
        ClientId = ClientId
    };
    
    var instanceIdResult = await instanceIdRequest.Perform();
    
    if(instanceIdResult.Status == ResponseStatus.Success) {
        InstanceId = instanceIdResult.InstanceId;
    }
  2. Create payment(ru):

    var p2P = new P2PRequestPaymentParams {
        AmountDue = "Sum to pay", To = "User login", Message = "..."
    };
    
    var reqParams = new PhoneTopupRequestPaymentParams
    {
        Amount = "Sum to pay",
        PhoneNumber = "..."
    };
    
    var requestExternalPaymentRequest = new RequestExternalPaymentRequest<RequestExternalPaymentResult> (
            defaultHttpPostClient, new JsonSerializer<RequestExternalPaymentResult> ()) {
        PaymentParams = reqParams.GetParams(),
        InstanceId = InstanceId
    };
    
    var requestPaymentResult = await requestExternalPaymentRequest.Perform();
    
    if(requestPaymentResult.Status == ResponseStatus.Success) {
        // success
    }
  3. Confirm payment(ru):

     var processExternalPaymentRequest = new ProcessExternalPaymentRequest<ProcessExternalPaymentResult> (
            defaultHttpPostClient, new JsonSerializer<ProcessExternalPaymentResult>()) {
        RequestId = requestPaymentResult.RequestID,
        InstanceId = InstanceId,
        ExtAuthSuccessUri = "...",
        ExtAuthFailUri = "...",
     };
    
     var processPaymentResult = await processExternalPaymentRequest.Perform();
     
     if(processPaymentResult.Status == ResponseStatus.Success) {
        // success
     }
    
     if(processPaymentResult.Status == ResponseStatus.ExtAuthRequired) {
    
        WebBrowser.Navigate(processPaymentResult.AcsUri, processPaymentResult.AcsParams);
     }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%