README.md in yandex-money-sdk-0.11.0 vs README.md in yandex-money-sdk-1.0.5

- old
+ new

@@ -52,39 +52,44 @@ 1. Obtain token URL and redirect user's browser to Yandex.Money service. Note: `client_id`, `redirect_uri`, `client_secret` are constants that you get, when [register](https://sp-money.yandex.ru/myservices/new.xml) app in Yandex.Money API. ```ruby - api = YandexMoney::Api.new( - client_id: CLIENT_ID, - redirect_uri: REDIRECT_URI, - scope: "account-info operation-history" + auth_url = YandexMoney::Wallet.build_obtain_token_url( + CLIENT_ID, + REDIRECT_URI, + "account-info operation-history" # SCOPE ) - auth_url = api.client_url ``` 2. After that, user fills Yandex.Money HTML form and user is redirected back to `REDIRECT_URI?code=CODE`. 3. You should immediately exchange `CODE` with `ACCESS_TOKEN`. ```ruby - api = YandexMoney::Api.new( - client_id: CLIENT_ID, - redirect_uri: REDIRECT_URI, - scope: "account-info operation-history" + access_token = YandexMoney::Wallet.get_access_token( + CLIENT_ID, + CODE, + REDIRECT_URI ) - api.code = params[:code] # obtained code - access_token = api.obtain_token # or, if client secret defined: - # access_token = api.obtain_token(CLIENT_SECRET) + access_token = YandexMoney::Wallet.get_access_token( + CLIENT_ID, + CODE, + REDIRECT_URI, + CLIENT_SECRET + ) ``` + If `access_token` couldn't be obtained, `YandexMoney::ApiError` expection will be raised. + + 4. Now you can use Yandex.Money API. ```ruby - api = YandexMoney::Api.new(token: TOKEN) # TOKEN is obtained token + api = YandexMoney::Wallet.new(access_token) account_info = api.account_info balance = account_info.balance # and so on request_options = { "pattern_id": "p2p", @@ -114,26 +119,17 @@ 1. Fetch instantce-id(ussually only once for every client. You can store result in DB). ```ruby - api = YandexMoney::Api.new(client_id: CLIENT_ID) - response = api.get_instance_id # returns string, contains instance id - if reponse.status == "success" - instance_id = response.instance_id - else - # throw exception - end + instance_id = YandexMoney::ExternalPayment.get_instance_id(CLIENT_ID) ``` 2. Make request payment ```ruby - api = YandexMoney::Api.new( - client_id: CLIENT_ID, - instance_id: INSTANCE_ID - ) + api = YandexMoney::ExternalPayment.new(INSTANCE_ID) response = api.request_external_payment({ pattern_id: "p2p", to: "410011285611534", amount_due: "1.00", message: "test" @@ -146,11 +142,11 @@ ``` 3. Process the request with process-payment. ```ruby - api = YandexMoney::Api.new(instance_id: INSTANCE_ID) + api = YandexMoney::ExternalPayment.new(INSTANCE_ID) result = api.process_external_payment({ request_id: REQUEST_ID, ext_auth_success_uri: "http://example.com/success", ext_auth_fail_uri: "http://example.com/fail" }) @@ -158,6 +154,6 @@ ``` ## Running tests -Just run it with `bundle exec rake` command. +Fill values in `spec/support/constants.rb` file (example could be found in `spec/support/constants.example.rb`) and after this just run tests with `bundle exec rake` command.