Skip to content

Commit

Permalink
Fix tests and update readme to use env vars instead of settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Oct 19, 2023
1 parent 4248c9d commit d1ea302
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 52 deletions.
41 changes: 7 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,18 @@ integration with the CyberSource REST APIs through the [CyberSource Ruby SDK](ht
```
$ git clone https://github.com/sul-dlss/cybersource-rest-ruby
```
* Install the cybersource-rest-client-ruby (from RubyGems.org)
* Install the gems
```
$ gem install cybersource_rest_client
$ bundle
```
* Run the report:
* Run the test report:
```
$ STAGE=dev ruby cyber_source/download_payment_batch_detail_report.rb
$ SLEEP=0 rspec
```

## Setting the API credentials for an API request

Configure the following information in the settings file:

* Http Signature
```yml
configurationDictionary:
merchantID: 'wfgsulair'
runEnvironment: 'cybersource.environment.production'
timeout: 1000 # In Milliseconds
authenticationType: 'http_signature'
enableLog: false
merchantsecretKey: 'your_key_serial_number'
merchantKeyId: 'your_key_shared_secret'
```
Configure the `MERCHANT_ID_KEY` and `MERCHANT_SECRET_KEY` variables in the environment as well as the `STAGE`, `APP_PASSWORD` (for folio) and `APP_USERNAME`

Obtain the merchantsecretKey and merchantKeyId from the CyberSource Business Center.
You will need permissions from merchants@stanford.edu to access the CyberSource Business Center
Expand All @@ -45,23 +33,8 @@ with the option to generate security keys.
## Switching between the sandbox environment and the production environment
CyberSource maintains a complete sandbox environment for testing and development purposes. This sandbox environment is an exact
duplicate of our production environment with the transaction authorization and settlement process simulated. By default, this sample code is
configured to communicate with the sandbox environment. To switch to the production environment, set the appropriate environment
constant in config/settings/#{stage} file. For example:
#### For PRODUCTION use
```yml
configurationDictionary:
merchantID: 'wfgsulair'
runEnvironment: 'cybersource.environment.production'
...
```
#### For TESTING use
```yml
configurationDictionary:
merchantID: 'wfgsulair'
runEnvironment: 'cybersource.environment.sandbox'
...
```
configured to communicate with the sandbox environment.
To switch to the sandbox environment, set the `CYBS_ENV=sandbox` environment variable.

## CyberSource API Reference

Expand Down
5 changes: 1 addition & 4 deletions cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ spec:
imagePullSecrets:
- name: ghcr
containers:
- image: ghcr.io/sul-dlss/cybersource-rest-ruby:cybersource-folio
- image: ghcr.io/sul-dlss/cybersource-rest-ruby:main
name: cybersource
env:
- name: OKAPI_URL
value: http://okapi:9130
envFrom:
- secretRef:
name: cybersource
Expand Down
9 changes: 5 additions & 4 deletions cyber_source/download_payment_batch_detail_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DownloadPaymentBatchDetailReport

CONFIGURATION_DICTIONARY = {
merchantID: 'wfgsulair',
runEnvironment: 'cybersource.environment.production',
runEnvironment: "cybersource.environment.#{ENV.fetch('CYBS_ENV', 'production')}",
timeout: 3000,
authenticationType: 'http_signature',
enableLog: true,
Expand Down Expand Up @@ -86,7 +86,7 @@ def main
end
end
puts credits
sleep(ENV.fetch('SLEEP', 2))
sleep(ENV.fetch('SLEEP', 2)&.to_i)
end
credits.any? && CSV.open('files/credits.csv', 'w+') do |csv|
csv << credits.first.keys
Expand All @@ -96,6 +96,7 @@ def main
end
rescue StandardError => e
puts e.message
puts e.backtrace
end

def download_report(report_date)
Expand All @@ -109,8 +110,8 @@ def download_report(report_date)

def folio_client
FolioClient.configure(
url: ENV.fetch('OKAPI_URL', nil),
login_params: { 'username' => ENV.fetch('ADMIN_USER', nil), 'password' => ENV.fetch('ADMIN_PASSWORD', nil) },
url: ENV.fetch('OKAPI_URL', 'http://okapi:9130'),
login_params: { 'username' => ENV.fetch('APP_USERNAME', nil), 'password' => ENV.fetch('APP_PASSWORD', nil) },
okapi_headers: { 'X-Okapi-Tenant' => 'sul', 'User-Agent' => 'FolioApiClient' }
)
end
Expand Down
5 changes: 1 addition & 4 deletions debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ metadata:
name: cybersource
spec:
containers:
- image: ghcr.io/sul-dlss/cybersource-rest-ruby:cybersource-folio
- image: ghcr.io/sul-dlss/cybersource-rest-ruby:main
name: cybersource
env:
- name: OKAPI_URL
value: http://okapi:9130
envFrom:
- secretRef:
name: cybersource
Expand Down
10 changes: 5 additions & 5 deletions spec/download_payment_batch_detail_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
RSpec.describe DownloadPaymentBatchDetailReport do
let(:dstring) { Date.today.to_s }
let(:report) { described_class.new(dstring) }
let(:file) { File.join(Dir.pwd, 'credits.csv') }
let(:file) { File.join(Dir.pwd, 'files/credits.csv') }
let(:download_report) { File.read(File.join(Dir.pwd, 'spec', 'fixtures', 'report_file.csv')) }

before do
File.open(file, 'a+')

stub_request(:post, 'http://example.com/authn/login')
.with(body: Settings.okapi.login_params.to_h)
.with(body: { 'username' => 'username', 'password' => 'password' })

stub_request(:get, 'http://example.com/accounts')
stub_request(:get, "#{ENV['OKAPI_URL']}/accounts")
.with(query: hash_including)
.to_return(body: '{
"accounts": [
Expand All @@ -28,8 +28,8 @@
"metadata": {
"createdDate": "2023-10-10T09:33:55.532+00:00"
},
"userId": "b096e3ce-097b-4776-948a-7f6b649398f0",
"feeFineId": "cf238f9f-7018-47b7-b815-bb2db798e19f"
"userId": "f1cf56ef-5071-477f-b3ee-8779721a7f44",
"id": "cf238f9f-7018-47b7-b815-bb2db798e19f"
}
],
"totalRecords": 1
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/report_file.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
wfgsulair,PaymentBatchDetailReport_Daily_Classic,PaymentBatchDetail,1.10,2023-10-10T07:00:00Z to 2023-10-11T07:00:00Z,,,,,,,
batch_id,merchant_id,batch_date,request_id,merchant_ref_number,TransactionReferenceNumber,payment_type,currency,amount,ics_applications,status,transaction_date
21265991580,wfgsulair,2023-10-11T04:15:21Z,6969304358566698703248,b096e3ce-097b-4776-948a-7f6b649398f0,93211601,MasterCard,USD,35.00,"ics_bill,ics_auth",BATCHED,2023-10-10T09:33:55Z
21265991580,wfgsulair,2023-10-11T04:15:21Z,6969304358566698703248,f1cf56ef-5071-477f-b3ee-8779721a7f44,93211601,MasterCard,USD,35.00,"ics_bill,ics_auth",BATCHED,2023-10-10T09:33:55Z

0 comments on commit d1ea302

Please sign in to comment.