public async Task CheckIfPayerIsActiveSendsProperRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWithJson(new { result = true });
                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var remittances = new RemittancesClient(config);

                var result = await remittances.IsAccountHolderActive(new Party("0777000000", PartyIdType.Msisdn));

                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment(TokenPath))
                .WithVerb(HttpMethod.Post);
                httpTest.ShouldHaveCalled(
                    Settings.BaseUri.AppendPathSegment($"/remittance/v1_0/accountholder/msisdn/0777000000/active"))
                .WithVerb(HttpMethod.Get)
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithHeader("X-Target-Environment", "sandbox");
                Assert.True(result);
            }
        }
        public async Task GetDisbursementSendsProperRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWithJson(new
                {
                    amount   = "25000.00",
                    currency = "UGX",
                    financialTransactionId = "XXXX",
                    externalid             = "YYYY",
                    payee = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    }
                });

                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var disbursements = new DisbursementsClient(config);

                var guid = Guid.NewGuid();

                var result = await disbursements.GetDisbursement(guid);

                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment(TokenPath))
                .WithVerb(HttpMethod.Post);
                httpTest.ShouldHaveCalled(
                    Settings.BaseUri.AppendPathSegment("/disbursement/v1_0/transfer").AppendPathSegment(guid))
                .WithVerb(HttpMethod.Get)
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("X-Target-Environment", "sandbox")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey);

                Assert.Equal(25000M, result.Amount);
                Assert.Equal("UGX", result.Currency);
                Assert.Equal("XXXX", result.FinancialTransactionId);
                Assert.Equal("YYYY", result.ExternalId);
                Assert.NotNull(result.Payee);
                Assert.Equal(PartyIdType.Msisdn, result.Payee.PartyIdType);
                Assert.Equal("0777000000", result.Payee.PartyId);
            }
        }
Beispiel #3
0
        public async Task NetworkErrorIsThrownWhenInvalidResponseIsReceived()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWithJson(new
                {
                    amount   = "xx25000.00xx",
                    currency = "UGX",
                    financialTransactionId = "XXXX",
                    externalid             = "YYYY",
                    payer = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    }
                });

                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var collections = new CollectionsClient(config);

                var guid = Guid.NewGuid();

                var result = await Record.ExceptionAsync(async() =>
                {
                    await collections.GetCollection(guid);
                });

                Assert.NotNull(result);
                Assert.IsType <NetworkException>(result);
            }
        }
        public async Task GetBalanceSendsProperRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWithJson(new
                {
                    availableBalance = "20000",
                    currency         = "UGX"
                });
                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var disbursements = new DisbursementsClient(config);

                var result = await disbursements.GetBalance();

                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment(TokenPath))
                .WithVerb(HttpMethod.Post);
                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment("/disbursement/v1_0/account/balance"))
                .WithVerb(HttpMethod.Get)
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithHeader("X-Target-Environment", "sandbox");

                Assert.Equal(20000, result.AvailableBalance);
                Assert.Equal("UGX", result.Currency);
            }
        }
        public async Task TransferSendsProperRequest()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWith(status: 202)
                .RespondWith(status: 202);

                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var disbursements = new DisbursementsClient(config);

                var resultWithCallback = await disbursements.Transfer(
                    25000.00M,
                    "UGX",
                    "XX",
                    new Party("0777000000", PartyIdType.Msisdn),
                    "YY",
                    "ZZ",
                    new Uri("http://www.example.com")
                    );

                var resultWithoutCallback = await disbursements.Transfer(
                    125000.00M,
                    "UGX",
                    "XY",
                    new Party("0777000000", PartyIdType.Msisdn),
                    "YDY",
                    "ZZM"
                    );

                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment(TokenPath))
                .WithVerb(HttpMethod.Post);
                httpTest.ShouldHaveCalled(
                    Settings.BaseUri.AppendPathSegment("/disbursement/v1_0/transfer"))
                .WithVerb(HttpMethod.Post)
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("X-Reference-Id", resultWithCallback.ToString())
                .WithHeader("X-Target-Environment", "sandbox")
                .WithHeader("X-Callback-Url", "http://www.example.com")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithRequestJson(new
                {
                    amount     = "25000.00",
                    currency   = "UGX",
                    externalId = "XX",
                    payee      = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    },
                    payerMessage = "YY",
                    payeeNote    = "ZZ",
                });
                httpTest.ShouldHaveCalled(
                    Settings.BaseUri.AppendPathSegment("/disbursement/v1_0/transfer"))
                .WithVerb(HttpMethod.Post)
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("X-Reference-Id", resultWithoutCallback.ToString())
                .WithHeader("X-Target-Environment", "sandbox")
                .WithoutHeader("X-Callback-Url")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithRequestJson(new
                {
                    amount     = "125000.00",
                    currency   = "UGX",
                    externalId = "XY",
                    payee      = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    },
                    payerMessage = "YDY",
                    payeeNote    = "ZZM",
                });
            }
        }
Beispiel #6
0
        public async Task MakingMultipleRequestsDoesNotRequestNewToken()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest
                .RespondWithJson(new
                {
                    access_token = Settings.AccessToken,
                    expires_in   = 3600,
                    token_type   = "access_token"
                })
                .RespondWithJson(new
                {
                    amount   = "20000.00",
                    currency = "UGX",
                    financialTransactionId = "XXXX",
                    externalid             = "YYYY",
                    payer = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    }
                })
                .RespondWithJson(new
                {
                    amount   = "30000.00",
                    currency = "UGX",
                    financialTransactionId = "XXXX",
                    externalid             = "YYYY",
                    payer = new
                    {
                        partyIdType = "MSISDN",
                        partyId     = "0777000000"
                    }
                });
                var config = new MomoConfig
                {
                    UserId          = Settings.UserId,
                    UserSecret      = Settings.UserSecretKey,
                    SubscriptionKey = Settings.SubscriptionKey
                };

                var collections = new CollectionsClient(config);

                var guid1 = Guid.NewGuid();
                var guid2 = Guid.NewGuid();

                var result1 = await collections.GetCollection(guid1);

                var result2 = await collections.GetCollection(guid2);

                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment(TokenPath))
                .WithHeader("Authorization",
                            Convert.ToBase64String(Encoding.UTF8.GetBytes($"{config.UserId}:{config.UserSecret}")))
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey);
                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment("/collection/v1_0/requesttopay").AppendPathSegment(guid1))
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithHeader("X-Target-Environment", "sandbox");
                httpTest.ShouldHaveCalled(Settings.BaseUri.AppendPathSegment("/collection/v1_0/requesttopay").AppendPathSegment(guid2))
                .WithHeader("Authorization", $"Bearer {Settings.AccessToken}")
                .WithHeader("Ocp-Apim-Subscription-Key", Settings.SubscriptionKey)
                .WithHeader("X-Target-Environment", "sandbox");

                Assert.Equal(20000, result1.Amount);
                Assert.Equal(30000, result2.Amount);
            }
        }