Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TEST_SECRET_KEY=
TEST_PUBLIC_KEY=
TEST_ENCRYPTION_KEY=
39 changes: 39 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--- Provide a general summary of your changes in the Title above -->

#### Description
<!--- Describe your changes in detail -->

#### Related Issue
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->

#### Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

#### How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

#### Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Refactor (non-breaking change which improves implementation)
- [ ] Performance (non-breaking change which improves performance. Please add associated performance test and results)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Non-functional change (xml comments/documentation/etc)

#### Checklist:
<!--- The following is a checklist of items that MUST be completed before a PR is accepted -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project.
- [ ] I have read the **CONTRIBUTING** [document](https://github.com/QuantConnect/Lean/blob/master/CONTRIBUTING.md).
- [ ] I have added tests to cover my changes. <!--- If not applicable, please explain why -->
- [ ] All new and existing tests passed.
- [ ] My branch follows the naming convention `bug-<issue#>-<description>` or `feature-<issue#>-<description>`


@Flutterwave/Corvus97 What do you think about these updates?
52 changes: 52 additions & 0 deletions .github/workflows/change-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Review changes on Dev (Commits/PRs)
on:
push:
branches: ["dev"]
pull_request:
types:
- opened

jobs:
code-check:
runs-on: ubuntu-latest

strategy:
matrix:
ruby-version: ["3.1", "3.0", "2.7"]

steps:
- name: checkout code
uses: actions/checkout@v2

- name: setup ruby environment
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby-version }}

- name: install ruby dependencies
run: |
gem install bundler
bundle install --jobs 4 --retry 3

- name: run unit tests and coverage scan
env:
PUBLIC_KEY: ${{ secrets.PUBLIC_KEY }}
ENCRYPTION_KEY: ${{ secrets.ENCRYPTION_KEY }}
RAVE_SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
bundle exec rspec --format progress --format json --out coverage/coverage.json

- name: upload coverage report to codecov
uses: codecov/codecov-action@v2
with:
file: coverage/coverage.json

- name: push build status to slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
65 changes: 65 additions & 0 deletions .github/workflows/ruby-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Publish changes to Rubygems

on:
release:
types: [created]

jobs:
check-readme-and-changelog:
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
ruby-version: "3.1"
steps:
- name: checkout code
uses: actions/checkout@v2

- name: check for changes in readme and changelog files
run: |
if ! git diff --quiet HEAD~ HEAD -- README.md CHANGELOG.md; then
echo "README and/or CHANGELOG have been modified. Proceeding with deployment."
else
echo "README and/or CHANGELOG have not been modified. Terminating deployment."
exit 1
fi

- name: push build status to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()

publish:
needs: check-readme-and-changelog
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
ruby-version: "3.1"
steps:
- name: checkout code
uses: actions/checkout@v2

- name: Setup ruby environment
uses: actions/setup-ruby@v1
with:
ruby-version: "3.1"

- name: install ruby dependencies
run: bundle install

- name: Publish gems to Rubygems
env:
GEM_HOST_API_KEY: ${{secrets.GEM_HOST_API_KEY}}
run: gem push gems/*.gem

- name: push build status to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
/tmp/

.env
/sample_code
sample_code/
sample_code

# rspec failure tracking
.rspec_status
Expand All @@ -33,4 +36,4 @@ virtual_account_number_test.rb
bills_test.rb
preauth_test.rb
rspec_results.html
flutterwave_sdk-0.1.0.gem
flutterwave_sdk-0.1.0.gem
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ PATH
remote: .
specs:
flutterwave_sdk (0.1.1)
httparty (~> 0.16.3)

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.3)
dotenv (2.8.1)
httparty (0.16.4)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
multi_xml (0.6.0)
rake (12.3.3)
rspec (3.9.0)
rspec-core (~> 3.9.0)
Expand All @@ -26,6 +35,8 @@ PLATFORMS
ruby

DEPENDENCIES
bundler (~> 2.1.4)
dotenv (~> 2.8.1)
flutterwave_sdk!
rake (~> 12.0)
rspec (~> 3.0)
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.1.1] - 2023-07-20
### Added
- Test suite for mobile money TZS transactions.
- Workflow scripts for review and publish

### Fixed
- Fix test suite for card.


## [0.1.1] - 2022-06-02
### Added
- Test suite for mobile money transactions.
Expand Down
8 changes: 8 additions & 0 deletions flutterwave_sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ spec.date = '2020-05-10'
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 2.1.4"
#add dotenv
spec.add_development_dependency "dotenv", "~> 2.8.1"

# Dependencies
spec.required_ruby_version = ">= 2.5.3"
spec.add_runtime_dependency 'httparty', '~> 0.16.3'
end
12 changes: 6 additions & 6 deletions lib/flutterwave_sdk/flutterwave_objects/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

class Card < CardBase

# method to initiate card charge
# method to initiate card charge
def initiate_charge(data)
base_url = flutterwave_object.base_url
encryption_key = flutterwave_object.encryption_key
public_key = flutterwave_object.public_key

# only update the payload with the transaction reference if it isn't already added to the payload
if !data.key?("tx_ref")
data.merge!({"tx_ref" => Util.transaction_reference_generator})
Expand All @@ -29,13 +29,13 @@ def initiate_charge(data)
type = "card"
payload = payload.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)

return response

end

def validate_charge(flw_ref, otp)
def validate_charge(flw_ref, otp)
base_url = flutterwave_object.base_url
payload = {
"otp" => otp,
Expand All @@ -52,4 +52,4 @@ def verify_charge(id)
response = get_request("#{base_url}/transactions/#{id}/verify")
return response
end
end
end
13 changes: 8 additions & 5 deletions lib/flutterwave_sdk/flutterwave_objects/mobile_money.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class MobileMoney < Base
def initiate_charge(data)
base_url = flutterwave_object.base_url
base_url = flutterwave_object.base_url

# only update the payload with the transaction reference if it isn't already added to the payload
if !data.key?("tx_ref")
data.merge!({"tx_ref" => Util.transaction_reference_generator})
end
# check the currency to determine the type and the required parameters
# check the currency to determine the type and the required parameters
if data["currency"] == "KES"
required_parameters = [ "amount", "email", "phone_number", "tx_ref", "currency"]
type = "mpesa"
Expand All @@ -22,12 +22,15 @@ def initiate_charge(data)
elsif data["currency"] == "ZMW"
required_parameters = ["amount", "email", "phone_number","tx_ref", "currency"]
type = "mobile_money_zambia"
elsif data["currency"] == "RWF"
elsif data["currency"] == "RWF"
required_parameters = ["amount", "email", "phone_number","tx_ref", "currency"]
type = "mobile_money_rwanda"
elsif data["currency"] == "XAF" || data["currency"] == "XOF"
required_parameters = ["amount", "email", "phone_number", "tx_ref", "currency"]
type = "mobile_money_franco"
elsif data["currency"] == "TZS"
required_parameters = ["amount", "email", "phone_number", "tx_ref", "currency"]
type = "mobile_money_tanzania"
else
return "pass a valid currency"
end
Expand All @@ -36,7 +39,7 @@ def initiate_charge(data)
type = type
payload = data.to_json

response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
response = post_request("#{base_url}#{BASE_ENDPOINTS::CHARGE_ENDPOINT}?type=#{type}", payload)
return response
end

Expand Down
22 changes: 11 additions & 11 deletions spec/flutterwave_card_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@

payload = {
"type" => "card",
"card_number" => "5531886652142950",
"cvv" => "564",
"card_number" => "4187427415564246",
"cvv" => "828",
"expiry_month" => "09",
"expiry_year" => "22",
"expiry_year" => "32",
"currency" => "NGN",
"amount" => "10",
"email" => "developers@flutterwavego.com",
"fullname" => "Ifunanya ikemma",
"tx_ref" => "Sample_RBRef218",
"tx_ref" => "MC-" + Date.today.to_s,
"redirect_url" => "https://webhook.site/3ed41e38-2c79-4c79-b455-97398730866c"
}

pin_payload = {
pin_payload = {
"type" => "card",
"card_number" => "5531886652142950",
"cvv" => "564",
"card_number" => "4187427415564246",
"cvv" => "828",
"expiry_month" => "09",
"expiry_year" => "22",
"expiry_year" => "32",
"currency" => "NGN",
"amount" => "10",
"email" => "developers@flutterwavego.com",
"fullname" => "Ifunanya ikemma",
"tx_ref" => "Sample_RBRef015",
"tx_ref" => "MC-" + Date.today.to_s,
"redirect_url" => "https://webhook.site/3ed41e38-2c79-4c79-b455-97398730866c",
"authorization": {
"mode": "pin",
Expand All @@ -46,12 +46,12 @@
# "card_number" => "5531886652142950",
"cvv" => "564",
"expiry_month" => "09",
"expiry_year" => "22",
"expiry_year" => "32",
"currency" => "NGN",
"amount" => "10",
"email" => "developers@flutterwavego.com",
"fullname" => "Ifunanya ikemma",
"tx_ref" => "MC-3243e-if-16",
"tx_ref" => "MC-" + Date.today.to_s,
"redirect_url" => "https://webhook.site/3ed41e38-2c79-4c79-b455-97398730866c"
}

Expand Down
Loading