Hi! Need help with xpay token generation foreignexchangerates (v2) api

Solved! Go to solution
sakshi
Regular Visitor

Hi! Need help with xpay token generation foreignexchangerates (v2) api

this is the method implementation for xpay token key generation.

secret = bytes(shared_secret, 'utf-8')
timestamp = str(timegm(datetime.datetime.utcnow().timetuple()))
pre_hash_string = bytes(timestamp + resource_path + query_string + body, 'utf-8')
print(pre_hash_string)
hash_string = hmac.new(secret, pre_hash_string, digestmod=hashlib.sha256).hexdigest()
x_pay_token = 'xv2:' + timestamp + ':' + hash_string

 

Below are the parameters for xpay token generation:

api_key = 'Z93UKQ5PDYB2W5H2YRD621kyUNDazyuhSJqh7T-rTRU0zsRxM'
shared_secret = 'E3K0YZ5XFG}6RarTa{Og1X-M2l{PqVnim@xIFKoH'
timeout = 10
query_string = "apiKey=" + api_key
resource_path = "forexrates/v2/foreignexchangerates"
body ='''{
"acquirerDetails": {
"bin": 408999,
"settlement": {
"currencyCode": "840"
}
},
"rateProductCode": "A",
"markupRate": "0.07",
"destinationCurrencyCode": "826",
"sourceAmount": "100.55",
"sourceCurrencyCode": "840"
}'''
Given below is post request:
 
databody = {
"acquirerDetails": {
"bin": 408999,
"settlement": {
"currencyCode": "840"
}
},
"rateProductCode": "A",
"markupRate": "0.07",
"destinationCurrencyCode": "826",
"sourceAmount": "100.55",
"sourceCurrencyCode": "840"
}
headers = {'x-pay-token': x_pay_token, 'accept':'application/json'}
response = requests.post(url + '?' + query_string,
headers=headers,
timeout=timeout,
data=databody
)
And this is the output:
 
{'responseStatus': {'status': 401, 'code': '9159', 'severity': 'ERROR', 'message': 'Token Validation Failed', 'info': ''}}
10 REPLIES 10
cathy2981
Community Moderator

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Thank you for your question, @sakshi . An agent will get back to you as soon as possible. In the meantime, if any community member knows the solution, please reply to this thread! -Cathy

API_Products
Visa Developer Support Specialist

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Hi @sakshi,

 

I just ran a sandbox test today and received a successful request/response payload. Please see my successful sample request/response below when I used the VDP Playground tool. Please try the test again and share your result with us.

 

End Point https://sandbox.api.visa.com/forexrates/v2/foreignexchangerates
Method POST
Request
{
"acquirerDetails": {
"bin": 408999,
"settlement": {"currencyCode": "840"}
},
"rateProductCode": "A",
"markupRate": "0.07",
"destinationCurrencyCode": "826",
"sourceAmount": "100.55",
"sourceCurrencyCode": "840"
}
Response
{
"rateProductCode": "A",
"acquirerDetails": {"settlement": {
"amount": "100.48",
"currencyCode": "840",
"conversionRate": "1.000000"
}},
"sourceAmountWithoutMarkup": "100.48",
"conversionRate": "0.7683121",
"destinationAmount": "77.20",
"markupRateApplied": "0.07"
}
Response Header
Status Code: 200 OK
Server : nginx
Date : Mon, 07 Feb 2022 18:08:48 GMT
Content-Type : application/json;charset=UTF-8
Content-Length : 246
Connection : keep-alive
X-SERVED-BY : l55c018
X-CORRELATION-ID : 1644257327_825_1884125905_l55c018_VDP_WS
X-APP-STATUS : 200
Content-Language : en-US
Cache-Control : no-cache, no-store, must-revalidate
X-Frame-Options : SAMEORIGIN
Pragma : no-cache
Expires : -1
X-XSS-Protection : 1; mode=block
X-Content-Type-Options : nosniff
Strict-Transport-Security : max-age=31536000;includeSubdomains;always

 

 

Below are the user guides for the tools that you can use to test the API.

 

VDP Playground – https://community.developer.visa.com/t5/Developer-Tools/How-to-test-and-troubleshoot-APIs-with-the-V...  

 

Postman – https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#testing_twoway_ssl_connectivity_...

 

SOAP UI – https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#testing_twoway_ssl_connectivity_...

 

Please refer to our Visa Developer Error Codes page for error codes and how to fix them here - https://developer.visa.com/pages/visa-developer-error-codes 

 

If the issue persists, please provide the following information:
1. Endpoint
2. Request Header
3. Request Body
4. Response Header (include the x-correlation-id)
5. Response Body
Using SoapUI, you can find the x-correlation-id in the Raw Tab of the response header.




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

sakshi
Regular Visitor

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Thanks Diana for the reply. But it seems you ain't using x-pay-token (where I'm currently stuck at!)

sakshi
Regular Visitor

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

These are my response headers
{'Server': 'nginx', 'Date': 'Mon, 07 Feb 2022 19:41:15 GMT', 'Content-Type': 'application/json', 'Content-Length': '112', 'Connection': 'keep-alive', 'X-SERVED-BY': 'l73c014', 'X-CORRELATION-ID': '1644262875_792_840475295_l73c014_VDP_WS', 'x-vdp-normalized-url': '/forexrates/v2/foreignexchangerates', 'X-APP-STATUS': '401', 'x-vdp-authn-api-visa-id': 'FX.100', 'X-ERROR-ORIGIN': '9100', 'X-Frame-Options': 'SAMEORIGIN', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '-1'}

API_Products
Visa Developer Support Specialist

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Hi @sakshi,

 

I did not use x-pay token. I used two-way SSL. The Foreign Exchange Rates authentication method is two-way SSL. Please use two-way SSL, test again and share your result with us. Here's the page link to the FX Rates authentication method: https://developer.visa.com/capabilities/foreign_exchange/docs-authentication  




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

sakshi
Regular Visitor

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Diana can you or someone from the team help me using the x-pay-token? I do not wish to use ssl
API_Products
Visa Developer Support Specialist

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Hi @sakshi,

 

Using the VDP Playground, I ran a sandbox test on FX Rates using x-pay token and received a successful request/response payload. Please see the sample request/response payload below. Try your test again and share your result with us.

 

End Point https://sandbox.api.visa.com/forexrates/v2/foreignexchangerates?apikey=P3WS07BT1O77E6W7EMHP21XbtZgvg...
Method POST
Request
{
"acquirerDetails": {
"bin": 408999,
"settlement": {"currencyCode": "840"}
},
"rateProductCode": "A",
"markupRate": "0.07",
"destinationCurrencyCode": "826",
"sourceAmount": "100.55",
"sourceCurrencyCode": "840"
}
Response
{
"rateProductCode": "A",
"acquirerDetails": {"settlement": {
"amount": "100.48",
"currencyCode": "840",
"conversionRate": "1.000000"
}},
"sourceAmountWithoutMarkup": "100.48",
"conversionRate": "0.7683121",
"destinationAmount": "77.20",
"markupRateApplied": "0.07"
}
Response Header
Status Code: 200 OK
Server : nginx
Date : Thu, 10 Feb 2022 19:14:00 GMT
Content-Type : application/json;charset=UTF-8
Content-Length : 246
Connection : keep-alive
X-SERVED-BY : f48d6589
X-CORRELATION-ID : 1644520440_678_886357006_f48d6589_VDP_WS
X-APP-STATUS : 200
Content-Language : en-US
Cache-Control : no-cache, no-store, must-revalidate
X-Frame-Options : SAMEORIGIN
X-XSS-Protection : 1; mode=block
X-Content-Type-Options : nosniff
Strict-Transport-Security : max-age=31536000;includeSubdomains
Pragma : no-cache
Expires : -1
X-XSS-Protection : 1; mode=block
X-Content-Type-Options : nosniff
Strict-Transport-Security : max-age=31536000;includeSubdomains;always

 




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.

sakshi
Regular Visitor

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Could you please tell me the body string for xpay token generation in python
API_Products
Visa Developer Support Specialist

Re: Hi! Need help with xpay token generation foreignexchangerates (v2) api

Hi @sakshi,

 

We only have the sample code that is available to you in your project under the Assets tab on the left side menu. Refer to sample screenshot below for reference.

20190801 Assets tab.png 




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.