require 'spec_helper' RSpec.describe PortalConnectors::MeshBankingClient do describe ".sign" do it "returns signature of request" do client = described_class.singleton params = { id: 1, account_username: "aUsername", } expect(client.sign(params)).to be_present end end describe "#check_stucked_payment", :vcr do context "server response with success status" do it "returns true" do client = described_class.new("vn") data, ok = client.check_stucked_payment("VND", "Vietcombank", 100_000) expect(ok).to be_truthy expect(data).to be_truthy end end context "with is_cashout_management is TRUE and server response with success status" do it "returns true" do client = described_class.new("vn") data, ok = client.check_stucked_payment("VND", "Vietcombank", 100_000, is_cashout_management: true) expect(ok).to be_truthy expect(data).to be_truthy end end end describe "#send_payment", :vcr do context "server response with success status" do it "returns true" do client = described_class.new("vn") data, ok = client.send_payment(bank_name: "Vietcombank", payment_details: { bank_account_number: "0123456789", bank_account_name: "NGUYEN THI BUOI" }, amount: 100_000, currency: "VND", payable: "ref0001") expect(ok).to be_truthy expect(data).to be_truthy end end context "with is_cashout_management is TRUE and server response with success status" do it "returns true" do client = described_class.new("vn") data, ok = client.send_payment(bank_name: "Vietcombank", payment_details: { bank_account_number: "0123456789", bank_account_name: "NGUYEN THI BUOI" }, amount: 100_000, currency: "VND", payable: "ref0001", is_cashout_management: true) expect(ok).to be_truthy expect(data).to be_truthy end end end describe "#request_fund_transfer", :vcr do context "server response with success status" do it "return fund transfer data" do client = described_class.new("vn") data, ok = client.request_fund_transfer( country_code: "vn", amount: 100_000, memo: "Pay to me", external_identifier: "trade:1", category_name: "auto_buy_usdt", external_payment_details: { bank_name: "Vietcombank", bank_account_number: "123456789", bank_account_name: "Nguyen van Ten" } ) expect(ok).to be_truthy expect(data["status"]).to eq("waiting_for_verify") end end end describe "#fetch_fund_transfer", :vcr do context "server response with success status" do it "return fund transfer data" do client = described_class.new("vn") data, ok = client.fetch_fund_transfer("fund_transfer-1") expect(ok).to be_truthy expect(data["status"]).to eq("pending") end end end describe "#fetch_auto_trade_action", vcr: true do context "server response with success status" do it "return auto trade action data" do client = described_class.new("vn") data, ok = client.fetch_auto_trade_action(1) expect(ok).to be_truthy expect(data["status"]).to eq("pending") end end end describe "#submit_auto_trade_action", vcr: :once do context "server response with error status" do it "returns error" do client = described_class.singleton params = { country_code: "vn", trade_type: "sell", coin_currency: "usdt", coin_amount: 100, min_expected_fiat_amount: 100 } data, ok = client.submit_auto_trade_action(params) expect(ok).to be_falsy expect(data["error"]).to eq("There is an error") end end context "server response with success status" do it "returns submitted auto trade action" do client = described_class.singleton params = { country_code: "vn", trade_type: "sell", coin_currency: "usdt", coin_amount: 100, min_expected_fiat_amount: 100 } data, ok = client.submit_auto_trade_action(params) expect(ok).to be_truthy expect(data["status"]).to eq("pending") end end end describe "#submit_account", :vcr do context "server response with error status" do it "returns error" do client = described_class.singleton credentials = { account_username: "aUsername", account_password: "paSswoRd", account_organization_id: "remitano", security_questions: {}, } params = { external_id: 1, bank_name: "Techcombank", credentials: credentials, account_number: "0251002746855", currency: "VND", for_testing: false, country_code: nil, remitano_username: "buyer", remitano_staff: false } data, ok = client.submit_account(params) expect(ok).to be_falsy expect(data["error"]).to eq("There are an error") end end context "server response with success status" do it "returns submitted account" do client = described_class.singleton credentials = { account_username: "aUsername", account_password: "paSswoRd", account_organization_id: "remitano", security_questions: {}, } params = { external_id: 1, bank_name: "Techcombank", credentials: credentials, account_number: "0251002746855", currency: "VND", for_testing: true, country_code: "vn", remitano_username: "buyer", remitano_staff: true } data, ok = client.submit_account(params) expect(ok).to be_truthy expect(data).to match( "id" => 1, "external_id" => 1, "bank_name" => "Techcombank", "account_name" => "Mac Thi Buoi", "balance" => "0.0", "currency" => "VND", "country_code" => "vn", "status_reason" => nil, "account_number" => "0251002746855", "status" => "verifying" ) end end end describe "#submit_sms_message", vcr: true do context "server response with error status" do it "returns error" do client = described_class.singleton message = <<~MESSAGE (TPBank) Ban dang Chuyen tien Nhanh toi TK 19029843081011 tren TK eBank So tien: 10,000 VND Ma OTP: 975104 KHONG TIET LO MA OTP CHO BAT KY AI MESSAGE params = { id: 1, message: message } data, ok = client.submit_sms_message(params) expect(ok).to be_falsy expect(data["error"]).to eq("There is an error") end end context "server response with success status" do it "returns submitted sms_otp" do client = described_class.singleton message = <<~MESSAGE (TPBank) Ban dang Chuyen tien Nhanh toi TK 19029843081011 tren TK eBank So tien: 10,000 VND Ma OTP: 975104 KHONG TIET LO MA OTP CHO BAT KY AI MESSAGE params = { id: 1, message: message } data, ok = client.submit_sms_message(params) expect(ok).to be_truthy expect(data["id"]).to eq(1) expect(data["bank_client_id"]).to eq(1) expect(data["status"]).to eq("provided") expect(data["otp"]).to eq("975104") expect(data["details"]).to eq({ "cash_amount" => "10000", "payee_account_no" => "19029843081011" }) expect(data["original_message"]).to eq(message) end end end describe "#submit_email_otp", :vcr do context "server response with error status" do it "returns error" do client = described_class.singleton params = { receiver_email: "test@example.com", content: "test content" } data, ok = client.submit_email_otp(params) expect(ok).to be_falsy expect(data["error"]).to eq("There is an error") end end context "server response with success status" do it "returns submitted email_otp" do client = described_class.singleton content = <<~MESSAGE (TPBank) Ban dang Chuyen tien Nhanh toi TK 19029843081011 tren TK eBank So tien: 10,000 VND Ma OTP: 975104 KHONG TIET LO MA OTP CHO BAT KY AI MESSAGE params = { content: content, receiver_email: "test@example.com" } data, ok = client.submit_email_otp(params) expect(ok).to be_truthy expect(data["id"]).to eq(1) expect(data["receiver_email"]).to eq("test@example.com") expect(data["content"]).to eq(content) end end end describe "#update_account", :vcr do context "server response with error status" do it "returns error" do client = described_class.singleton params = { id: 1, security_amount: 0.0, discarded_at_timestamp: Time.now.to_i, removal_requested: false } data, ok = client.update_account(params) expect(ok).to be_falsy expect(data["error"]).to eq("There is an error") end end context "server response with success status" do it "returns submitted account" do client = described_class.singleton params = { id: 1, security_amount: 99_000_000.0, discarded_at_timestamp: nil, removal_requested: true } data, ok = client.update_account(params) expect(ok).to be_truthy expect(data).to match( "id" => 1, "external_id" => 1, "bank_name" => "Techcombank", "account_name" => "Luu Diec Phi", "balance" => "0.0", "currency" => "VND", "country_code" => "vn", "account_number" => "0251002746855", "status" => "verified", "security_amount" => "99000000.0", "removal_requested" => true ) end end end describe "#request_virtal_bank_account", :vcr do context "server response with error status" do it "returns error" do client = described_class.new("in") params = { user_id: 27, username: "song_zuer", user_phone_number: "+911234567890", user_email: "song_zuer@remitano.com" } data, ok = client.request_virtal_bank_account(params) expect(ok).to be false expect(data["error"]).to eq("Bank client is not available") end end context "server response with success status" do it "returns the VBA info" do client = described_class.new("in") params = { user_id: 27, username: "song_zuer", user_phone_number: "+911234567890", user_email: "song_zuer@remitano.com" } data, ok = client.request_virtal_bank_account(params) expect(ok).to be true expect(data).to eq( "requester" => "song_zuer", "bank_name" => "Cashfree", "bank_account_name" => "Remitano Technology Private Limited", "bank_account_number" => "363636300000000001", "ifsc_code" => "YESB0C00001", "country_code" => "in" ) end end end describe "#request_stitch_linked_bank_account", :vcr do context "server response with error status" do it "returns error" do client = described_class.new("za") data, ok = client.request_stitch_linked_bank_account( currency: "ZAR", requester: "zu_xao_ma", user_level: 1, user_email: "zu_xao_ma@gmail.com", options: { user_real_name: "Zu Xao" } ) expect(ok).to be false expect(data["error"]).to eq("There is no available Stitch bank client now") end end context "server response with failed status" do it "returns error status from LBA" do client = described_class.new("za") data, ok = client.request_stitch_linked_bank_account( currency: "ZAR", requester: "zu_xao_ma", user_level: 1, user_email: "zu_xao_ma@gmail.com", options: { user_real_name: "Zu Xao" } ) expect(ok).to be false expect(data["error"]).to eq("Request Stitch payment authorization request failed") expect(data["stitch_lba_status"]).to eq("request_par_failed") end end context "server response with success status" do it "returns LBA info" do client = described_class.new("za") data, ok = client.request_stitch_linked_bank_account( currency: "ZAR", requester: "zu_xao_ma", user_level: 1, user_email: "zu_xao_ma@gmail.com", options: { user_real_name: "Zu Xao" } ) expect(ok).to be true expect(data["payer_name"]).to eq("zu_xao_ma") expect(data["par_url"]).to be_include("https://secure.stitch.money/connect/authorization/6594fbd2-931f-458f-ba41-e028b9ea87e6") expect(data["par_url"]).to be_include("client_id=") expect(data["par_url"]).to be_include("code_challenge=") expect(data["par_url"]).to be_include("code_challenge_method=") expect(data["par_url"]).to be_include("nonce=") expect(data["par_url"]).to be_include("edirect_uri=") expect(data["par_url"]).to be_include("state=") end end end describe "#activate_stitch_linked_bank_account", :vcr do context "server response ok" do it "returns LBA info" do client = described_class.new("za") data, ok = client.activate_stitch_linked_bank_account( auth_code: "E-3-i6AqzY0xe8EuZK8sJqlqNz3VCxN2qBvqQAzVqVY", requester: "zu_xao_ma", state: "CLdx1eMkxPtxcbw0vxPwmOfaHGl7yAaoD28_rJT-66qrM22m9DZNaxo6ob0eHtnxP7iL_wYKq8xUQQ5SNs-pDw" ) expect(ok).to be true expect(data["logo"]).to eq("https://secure.stitch.money/v2/logos/institutions/fnb.svg") expect(data["linked_ba_name"]).to eq("FNB Premier Cheque Account") expect(data["linked_ba_number"]).to eq("62120098985") end end end describe "#cancel_activation_stitch_linked_bank_account", :vcr do context "not found lba" do it "returns error" do client = described_class.new("za") data, ok = client.cancel_activation_stitch_linked_bank_account( requester: "zu_xao_ma", state: "CLdx1eMkxPtxcbw0vxPwmOfaHGl7yAaoD28_rJT-66qrM22m9DZNaxo6ob0eHtnxP7iL_wYKq8xUQQ5SNs-pDw" ) expect(ok).to be false expect(data["error"]).to eq("Stitch linked bank account is not found") end end context "cancel success" do it "returns lba info" do client = described_class.new("za") data, ok = client.cancel_activation_stitch_linked_bank_account( requester: "zu_xao_ma", state: "CLdx1eMkxPtxcbw0vxPwmOfaHGl7yAaoD28_rJT-66qrM22m9DZNaxo6ob0eHtnxP7iL_wYKq8xUQQ5SNs-pDw" ) expect(ok).to be true expect(data["linked_ba_name"]).to eq("FNB Premier Cheque Account") expect(data["linked_ba_number"]).to eq("62120098985") end end end describe "#fetch_available_bank_names", :vcr do context "server response with error status" do it "returns error" do client = described_class.new("vn") params = { user_level: 1 } data, ok = client.fetch_available_bank_names(params) expect(ok).to be false expect(data["error"]).to eq("error") end end context "server response with success status" do it "returns bank names" do client = described_class.new("vn") params = { user_level: 4 } data, ok = client.fetch_available_bank_names(params) expect(ok).to be true expect(data["bank_names"]).to match_array(%w[Techcombank]) end end end describe "#fetch_available_deposit_options", :vcr do context "server response with error status" do it "returns error" do client = described_class.new("za") params = { user_level: 1, requester: "songzuer" } data, ok = client.fetch_available_deposit_options(params) expect(ok).to be_falsy expect(data["error"]).to eq("Wrong signature") end end context "server response with success status" do it "returns bank names and stitch linked accounts" do client = described_class.new("za") params = { user_level: 4, requester: "songzuer" } data, ok = client.fetch_available_deposit_options(params) expect(ok).to be true expect(data["bank_names"]).to eq(["Capitec Bank", "Stitch"]) expect(data["stitch_linked_accounts"]).to eq([ { "id" => 1, "linked_ba_name" => "John To Moon", "linked_ba_number" => "123456789458", "linked_ba_type" => "current", "linked_bank_id" => "nedbank" } ]) end end end describe "#statistics", :vcr do context "server response with success status" do it "returns statistics" do client = described_class.new("vn") data, ok = client.statistics expect(ok).to be true expect(data).to eq( { "deposited_amount" => "0.0", "high_level_agency_depositable_amount" => 0, "high_level_user_depositable_amount" => 0, "low_level_agency_depositable_amount" => 0, "low_level_user_depositable_amount" => 0, "max_one_time_external_sendable_amount" => 50000.0, "max_one_time_internal_sendable_amount" => 50000.0, "total_today_external_sendable_amount" => 50000.0, "total_today_internal_sendable_amount" => 50000.0, "withdrew_amount" => "0.0" } ) end end end describe "#balance", :vcr do context "server response with success status" do it "returns total balance" do client = described_class.new("vn") data, ok = client.balance expect(ok).to be true expect(data).to eq( { "total_balance" => "600000000.0" } ) end end end describe "#fiat_minted", :vcr do context "server response with success status" do it "returns fiat minted" do client = described_class.new("vn") data, ok = client.fiat_minted(from_time: 30.days.ago.to_i) expect(ok).to be true expect(data).to eq( { "total_minted" => "500000.0" } ) end end end end