-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5830bd4
commit ca50677
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# SWIFT-EA | ||
Chainlink external adapter that allows SWIFT financial messages to be accessed by the blockchain or smart contract | ||
|
||
|
||
# Solidity Example Integration: | ||
Declare UETR ID for desired Transaction | ||
req.add("UETR", "d2ecb184-b622-11e9-a2a3-2a2ae2dbcce4") | ||
|
||
GET status via HTTP request from options listed on: https://developer.swift.com/content/tracker-reference#tag/Get-Payment-Transaction-Details | ||
req.add("status", "transactions") or "changed/transactions" | ||
|
||
Declare your OAuth Basic 2.0 | ||
req.add("oauth", "YourSWIFT-APIOauthToken") | ||
|
||
# Example JSON Response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from bridge import Bridge | ||
|
||
|
||
class Adapter: | ||
base_url = 'https://sandbox.swift.com/swift-apitracker/v4/payments' # '/{uetr}/status' needs to be appended | ||
from_params = ['base', 'UETR', 'transaction'] | ||
action_params = ['cancellation', 'status', 'transactions'] | ||
oauth_token = ['oauth', 'token', 'oauth_token'] | ||
|
||
def __init__(self, input): | ||
self.id = input.get('id', '1') | ||
self.request_data = input.get('data') | ||
if self.validate_request_data(): | ||
self.bridge = Bridge() | ||
self.set_params() | ||
self.create_request() | ||
else: | ||
self.result_error('No data provided') | ||
|
||
def validate_request_data(self): | ||
if self.request_data is None: | ||
return False | ||
if self.request_data == {}: | ||
return False | ||
return True | ||
|
||
def set_params(self): | ||
for param in self.from_params: | ||
self.from_param = self.request_data.get(param) | ||
if self.from_param is not None: | ||
break | ||
for param in self.action_params: | ||
self.to_param = self.request_data.get(param) | ||
if self.to_param is not None: | ||
break | ||
for param in self.oauth_token: | ||
self.oauth = self.request_data.get(param) | ||
if self.oauth is not None: | ||
break | ||
|
||
def create_request(self): | ||
try: | ||
# | ||
headers = {"Authorization": "Basic "+self.oauth} | ||
self.base_url += "/"+self.from_param+"/"+self.to_param | ||
# | ||
response = self.bridge.request(self.base_url, headers) | ||
data = response.json() | ||
|
||
# self.result = data[self.to_param] | ||
self.result = data["return"] # might need to switch to '' | ||
data['result'] = self.result | ||
self.result_success(data) | ||
|
||
except Exception as e: | ||
self.result_error(e) | ||
finally: | ||
self.bridge.close() | ||
|
||
def result_success(self, data): | ||
self.result = { | ||
'jobRunID': self.id, | ||
'data': data, | ||
'result': self.result, | ||
'statusCode': 200, | ||
} | ||
|
||
def result_error(self, error): | ||
self.result = { | ||
'jobRunID': self.id, | ||
'status': 'errored', | ||
'error': f'There was an error: {error}', | ||
'statusCode': 500, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# to execute pytest: pipenv run pytest -rP | ||
|
||
import pytest | ||
import adapter | ||
|
||
|