-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PAYOP-1116] Refine network token module interface (#330)
* Combine module * Remove raw value parameters * Rename tests * Fix doc
- Loading branch information
1 parent
42a83fb
commit b790c86
Showing
6 changed files
with
164 additions
and
257 deletions.
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
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,79 @@ | ||
load("@vgs//native_nts", _nts="native_nts") | ||
load("@stdlib//larky", larky="larky") | ||
load("@vendor//jsonpath_ng", jsonpath_ng="jsonpath_ng") | ||
|
||
|
||
def render( | ||
input, | ||
pan, | ||
cvv, | ||
amount, | ||
currency_code, | ||
exp_month=None, | ||
exp_year=None, | ||
cryptogram_value=None, | ||
cryptogram_eci=None, | ||
): | ||
"""Retrieves a network token for the given PAN alias, renders the cryptogram, and injects the network token values | ||
into the payload. | ||
For the output JSONPaths, please note that inserting a value into a non-existing deep nested note is not currently | ||
supported. For example, for an input payload like this:: | ||
input = { | ||
"data": {} | ||
} | ||
To insert into `$.data.network_token.exp_month` JSONPath, you need to place any value at the exact path first | ||
like this in order to make JSONPath value insertion work:: | ||
input["data"]["network_token"] = {"exp_month": "TO_BE_REPLACED"} | ||
nts.render(input, ...) | ||
:param input: JSON payload to inject network token into | ||
:param pan: JSONPath to the PAN alias in the input payload. Used to look up the corresponding network token to be | ||
rendered and injected into the payload. | ||
:param cvv: JSONPath to the CVV of the credit card in the input payload. Used to pass to the network for retrieving | ||
the corresponding network token and cryptogram to be returned. | ||
:param amount: JSONPath to the amount of payment for the transaction to be made with the network token in the input | ||
payload. Used to pass to the network for retrieving the corresponding network token and cryptogram to be | ||
returned. | ||
:param currency_code: JSONPath to the currency code of payment amount for the transaction to be made with the | ||
network token in the input payload. Used to pass to the network for retrieving the corresponding network | ||
token and cryptogram to be returned. | ||
:param exp_month: JSONPath to insert the expiration month of the network token within the input payload | ||
:param exp_year: JSONPath to insert the expiration year of the network token within the input payload | ||
:param cryptogram_value: JSONPath to insert the cryptogram value of the network token within the input | ||
payload | ||
:param cryptogram_eci: JSONPath to insert the cryptogram ECI of the network token within the input payload | ||
:return: JSON payload injected with network token values | ||
""" | ||
pan_value = jsonpath_ng.parse(pan).find(input).value | ||
cvv_value = jsonpath_ng.parse(cvv).find(input).value | ||
amount_value = str(jsonpath_ng.parse(amount).find(input).value) | ||
currency_code_value = jsonpath_ng.parse(currency_code).find(input).value | ||
|
||
network_token = _nts.get_network_token( | ||
pan=pan_value, | ||
cvv=cvv_value, | ||
amount=amount_value, | ||
currency_code=currency_code_value, | ||
) | ||
placements = [ | ||
(pan, network_token["token"]), | ||
(exp_month, network_token["exp_month"]), | ||
(exp_year, network_token["exp_year"]), | ||
(cryptogram_value, network_token["cryptogram_value"]), | ||
(cryptogram_eci, network_token["cryptogram_eci"]), | ||
] | ||
for path, value in placements: | ||
if path == None: | ||
continue | ||
input = jsonpath_ng.parse(path).update(input, value).value | ||
return input | ||
|
||
|
||
nts = larky.struct( | ||
get_network_token=_nts.get_network_token, | ||
render=render, | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.