Skip to content

Commit dd96073

Browse files
committed
Refactor tests
1 parent 022d9d4 commit dd96073

8 files changed

Lines changed: 247 additions & 39 deletions

File tree

README.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,12 @@ collection = Momoapi::Collection.new
7070
```
7171

7272
### Methods
73-
1. `request_to_pay`: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. Status of the transaction can be validated by using `get_transaction_status`.
73+
1. `request_to_pay`: This operation is used to request a payment from a consumer (Payer). The payer will be asked to authorize the payment. The transaction is executed once the payer has authorized the payment. The transaction will be in status PENDING until it is authorized or declined by the payer or it is timed out by the system. The status of the transaction can be validated by using `get_transaction_status`.
7474

75-
2. `get_transaction_status`: Retrieve transaction information using the `transaction_id` returned by `request_to_pay`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
75+
2. `get_transaction_status`: Retrieve transaction information using the `transaction_reference` returned by `request_to_pay`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
7676

7777
3. `get_balance`: Get the balance of the account.
7878

79-
### Sample Code
80-
81-
```ruby
82-
require 'momoapi-ruby'
83-
84-
collection = Momoapi::Collection.new
85-
collection.request_to_pay(
86-
phone_number="256772123456", amount=600, external_id="123456789", payee_note="dd", payer_message="dd", currency="EUR")
87-
```
88-
An extra argument, `callback_url`, can be passed to this method, denoting the URL to the server where the callback should be sent.
8979

9080
## Disbursements
9181
The disbursements client can be created with the following paramaters. The `DISBURSEMENT_USER_ID` and `DISBURSEMENT_API_SECRET` for production are provided on the MTN OVA dashboard.
@@ -110,22 +100,12 @@ disbursement = Momoapi::Disbursement.new
110100
```
111101

112102
### Methods
113-
1. `transfer`: Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the `get_transaction_status` method.
103+
1. `transfer`: Used to transfer an amount from the owner’s account to a payee account. The status of the transaction can be validated by using the `get_transaction_status` method.
114104

115-
2. `get_transaction_status`: Retrieve transaction information using the `transaction_id` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
105+
2. `get_transaction_status`: Retrieve transaction information using the `transaction_reference` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
116106

117107
3. `get_balance`: Get the balance of the account.
118108

119-
### Sample Code
120-
121-
```ruby
122-
require 'momoapi-ruby'
123-
124-
disbursement = Momoapi::Disbursement.new
125-
disbursement.transfer(
126-
phone_number="256772123456", amount=600, external_id="123456789", payee_note="dd", payer_message="dd", currency="EUR")
127-
```
128-
An extra argument, `callback_url`, can be passed to this method, denoting the URL to the server where the callback should be sent.
129109

130110
## Remittances
131111
The remittances client can be created with the following paramaters. The `REMITTANCES_USER_ID` and `REMITTANCES_API_SECRET` for production are provided on the MTN OVA dashboard.
@@ -150,22 +130,39 @@ remittance = Momoapi::Remittance.new
150130
```
151131

152132
### Methods
153-
1. `transfer`: Used to transfer an amount from the owner’s account to a payee account. Status of the transaction can be validated by using the `get_transaction_status` method.
133+
1. `transfer`: Used to transfer an amount from the owner’s account to a payee account. The status of the transaction can be validated by using the `get_transaction_status` method.
154134

155-
2. `get_transaction_status`: Retrieve transaction information using the `transaction_id` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
135+
2. `get_transaction_status`: Retrieve transaction information using the `transaction_reference` returned by `transfer`. You can invoke it at intervals until the transaction fails or succeeds. If the transaction has failed, it will throw an appropriate error.
156136

157137
3. `get_balance`: Get the balance of the account.
158138

159-
### Sample Code
139+
140+
## Sample Code
160141

161142
```ruby
162143
require 'momoapi-ruby'
163144

164-
remittance = Momoapi::Remittance.new
165-
remittance.transfer(
145+
collection = Momoapi::Collection.new
146+
147+
collection.is_user_active('256772123456')
148+
149+
collection.get_balance
150+
151+
transaction = collection.request_to_pay(
166152
phone_number="256772123456", amount=600, external_id="123456789", payee_note="dd", payer_message="dd", currency="EUR")
153+
154+
transaction_ref = transaction[:transaction_reference]
155+
156+
collection.get_transaction_status(transaction_ref)
157+
167158
```
168-
An extra argument, `callback_url`, can be passed to this method, denoting the URL to the server where the callback should be sent.
159+
160+
### Points to note:
161+
All methods for Disbursements and Remittances follow the same format as the examples shown above for Collections
162+
163+
The 'transfer' method for Disbursements and Remittances follows the same format as 'request_to_pay' above.
164+
165+
An extra argument, `callback_url`, can be passed to the 'request_to_pay' and 'transfer' methods, denoting the URL to the server where the callback should be sent.
169166

170167

171168
## Contributing

lib/momoapi-ruby/cli.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def initialize(option)
2121
create_sandbox_user
2222
end
2323

24+
# Create an API user in the sandbox target environment
2425
def create_sandbox_user
2526
body = { "providerCallbackHost": @host }
26-
@url = 'https://sandbox.momodeveloper.mtn.com/v1_0/apiuser'
27+
@url = 'https://ericssonbasicapi2.azure-api.net/v1_0/apiuser'
2728
response = Faraday.post(@url) do |req|
2829
req.headers['Content-Type'] = 'application/json'
2930
req.headers['X-Reference-Id'] = @uuid
@@ -38,8 +39,9 @@ def create_sandbox_user
3839
generate_api_key
3940
end
4041

42+
# Generate an API key in the sandbox target environment
4143
def generate_api_key
42-
@url = 'https://sandbox.momodeveloper.mtn.com/v1_0/apiuser/' +
44+
@url = 'https://ericssonbasicapi2.azure-api.net/v1_0/apiuser/' +
4345
@uuid + '/apikey'
4446
response = Faraday.post(@url) do |req|
4547
req.headers['Ocp-Apim-Subscription-Key'] = @key

spec/cassettes/Momoapi_Collection/collections/gets_transaction_status.yml

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/Momoapi_Disbursement/disbursements/checks_if_user_is_active.yml

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/cassettes/Momoapi_Remittance/remittances/checks_if_user_is_active.yml

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/features/collection_spec.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515

1616
describe 'collections', vcr: { record: :new_episodes } do
1717
it 'checks if user is active' do
18-
# response = Momoapi::Collection.new.is_user_active('0243656543')
19-
# expect(response[:code]).to eq(200)
20-
expect { Momoapi::Collection.new.is_user_active('0243656543') }
21-
.to raise_error(Momoapi::Error)
18+
response = Momoapi::Collection.new.is_user_active('0243656543')
19+
expect(response).to be_a_kind_of(Hash)
2220
end
2321

2422
it 'gets balance' do
@@ -27,9 +25,7 @@
2725
end
2826

2927
it 'gets transaction status' do
30-
ref = '888a79ff-0535-4a9f-8a66-457f7903bd8a'
31-
# response = Momoapi::Collection.new.get_transaction_status(ref)
32-
# expect(response[:code]).to eq(200)
28+
ref = '3700b523-c5d9-446e-8c01-a6261903a9ba'
3329
expect { Momoapi::Collection.new.get_transaction_status(ref) }
3430
.to raise_error(Momoapi::Error)
3531
end

spec/features/disbursement_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
end
1515

1616
describe 'disbursements', vcr: { record: :new_episodes } do
17+
it 'checks if user is active' do
18+
response = Momoapi::Disbursement.new.is_user_active('0243656543')
19+
expect(response).to be_a_kind_of(Hash)
20+
end
21+
1722
it 'gets balance' do
1823
expect { Momoapi::Disbursement.new.get_balance }
1924
.to raise_error(Momoapi::Error)

spec/features/remittance_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
end
1515

1616
describe 'remittances', vcr: { record: :new_episodes } do
17+
it 'checks if user is active' do
18+
response = Momoapi::Remittance.new.is_user_active('0243656543')
19+
expect(response).to be_a_kind_of(Hash)
20+
end
21+
1722
it 'gets balance' do
1823
expect { Momoapi::Remittance.new.get_balance }
1924
.to raise_error(Momoapi::Error)

0 commit comments

Comments
 (0)