I am building a payment integration from 3rd party api. After I send the request I am getting this response from terminal. What I need is to get the token in form at view. How can I access the token value?
Started GET "/charges/charge" for 127.0.0.1 at 2017-06-09 14:28:48 +0300
Processing by ChargesController#charge as HTML"{\"status\":\"success\",\"systemTime\":1497007730319,\"conversationId\":\"123456789\",\"token\":\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\",\"checkoutFormContent\":\"<script type=\\\"text/javascript\\\">if (typeof pay == 'undefined') {var pay = {token:\\\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\\\",price:1.20,}</script>\
This is the json response which you are getting from payment getway. So you will need to parse it.
You can parse this json response like this
response = "{\"status\":\"success\",\"systemTime\":1497007730319,\"conversationId\":\"123456789\",\"token\":\"4d4b7364-acf7-45df-9fbc-d680212ab9ba\"}"
parsed_response = JSON.parse(response) # This will return you hash
token = parsed_response['token']
Related
In Postman, I am doing a GET request to obtain an OAuth token. In the API, the response gives me a login URL value where once decoded, I will then be re-directed to the 3rd party to then gain the token etc.
The API response however is not a JSON response. By default the value is a text response.
I am aware that to store a JSON value I would use syntax like the below:
var data = JSON.parse(responseBody);
postman.setEnvironmentVariable("login_url", data.login_url);
But how would I store the value if the response is not a JSON?
I am new to rest assured, I want to perform some get and post for test data generation using rest assured. But I am unable to get the LTPA token and pass them to post. This works with postman but I want to do it through java. Any help
final String uri = "https://XXXX/Rest/XXXXX?user=XXXXX&pass=XXXX";
final Response response = RestAssured.given().relaxedHTTPSValidation().accept(ContentType.JSON).get(uri);
System.out.println(response.prettyPrint());
Map<String, String> allCookies = response.cookies();
System.out.println(allCookies);
Output
{JSESSIONID=XXXXXXX:-1}
but i do not see the LTPA2 token
Your LTPA2 token must be in Response headers.
You can get the response headers by
response.headers ();
In case if LTPA token is also not available in headers then share the screenshot of postman so I can help you out.
I can not figure out what I'm doing wrong. I'm developing an App for BigCommerce and can not get the simple oAuth exchange to work correctly.
The initial get request is being made to https://www.my-app.com/oauth/bigcommerce/auth. This is the code in the controller for that request. It's a Laravel 5.6 app:
use Illuminate\Http\Request;
use Bigcommerce\Api\Client as Bigcommerce;
class BigcommerceOAuthController extends Controller
{
public function auth(Request $request)
{
$object = new \stdClass();
$object->client_id = 'my-client-id';
$object->client_secret = 'my-client-secret';
$object->redirect_uri = 'https://my-app.com/oauth/bigcommerce/auth';
$object->code = $request->get('code');
$object->context = $request->get('context');
$object->scope = $request->get('scope');
$authTokenResponse = Bigcommerce::getAuthToken($object);
$storeHash = str_replace('stores/', '', $request->get('context'));
Bigcommerce::configure(array(
'client_id' => 'my-client-id',
'auth_token' => $authTokenResponse->access_token,
'store_hash' => $storeHash
));
echo "<pre>";
print_r($authTokenResponse);
print_r(Bigcommerce::getTime());
echo "</pre>";
}
}
Every time I try to install my draft app from the BigCommerce control panel, I get an error because $authTokenResponse is not an object. When I debug further into the Bigcommerce\Api\Connection class, I can see that the response from the server is empty, and the status is a 401, which means "Unauthorized".
I can't figure out why I am getting this error. As far as I can see, I'm doing everything right. I've tried urlencoding the string retrieved from $request->get('scope'), since that string becomes unencoded by Laravel, but that didn't seem to help.
I am also confused how this is even supposed to work at all. In the BigCommerce docs, they show this example POST request, which uses application/x-www-form-urlencoded Content-Type and passes the request body as a url encoded string:
POST /oauth2/token HTTP/1.1 Host: login.bigcommerce.com Content-Type:
application/x-www-form-urlencoded Content-Length: 186
client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}&code=qr6h3thvbvag2ffq&scope=store_v2_orders&grant_type=authorization_code&redirect_uri=https://app.example.com/oauth&context=stores/{STORE_HASH}
However, if you inspect what's going on in the Connection class, you can see that the Content-Type is being set to application/x-www-form-urlencoded as the docs say, but the request body is being passed in as a json string, not a url string. Shouldn't the request be a url encoded string as the docs suggest?
A couple of things here to check:
Do you have a public URL where you can receive the Auth Callback?
If so, did the store owner registered the app successfully? https://developer.bigcommerce.com/api/registration
When you have the client_id and secret_id. You should have all of the details needed to send a POST request to the BC Auth Token Service at https://login.bigcommerce.com/oauth2/token
The content uses URL encode Make sure to URL encode your content. Be careful of of the encoding of & and = signs when those are actually being used as separators.
More details can be found in this post:
Can BigCommerce Private Apps use OAuth
I'm trying to use the PDT system on PayPal to manage payments on my site. My site is correctly receiving the transaction id which is sent back to paypal in order to receive the transaction data.
This is the code which I am using to post the transaction id to paypal and receive a response.
response = Net::HTTP.post_form(URI.parse("#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?"), values)
puts response.body
I am receiving the correct response where response.body shows this in the terminal.
SUCCESS
transaction_subject=SPORTS+PACKAGE+%281+Week%29
payment_date=23%3A32%3A01+Jul+20%2C+2017+PDT
txn_type=subscr_payment
subscr_id=I-WHFVMBY57NX2
last_name=Lucas
residence_country=US
item_name=SPORTS+PACKAGE+%281+Week%29
payment_gross=
mc_currency=AUD
business=merchant-success%40puntsquad.com
payment_type=instant
protection_eligibility=Ineligible
payer_status=verified
payer_email=buyer-success%40puntsquad.com
txn_id=8M5887849L359363Y
receiver_email=merchant-success%40puntsquad.com
first_name=George
payer_id=667TSNBH7R7X4
receiver_id=WJYE8WGSREP98
payment_status=Completed
payment_fee=
mc_fee=2.00
mc_gross=50.00
charset=windows-1252
My problem is I am unsure of how I am able to access these values.
You can convert the response body to a hash as follows
hsh = CGI::parse(response.body)
puts hsh['transaction_subject']
In my rails (3.2.13) app I send data to an external server using a form, then the external server process the data I sent and shows that the result is ok or not, I need to save that result or status to my rails app database, but I'm not sure about how to redirect to another page when the process in the external server is done.
I have a function to ask the server if the process of that data went ok using the reference or id that I sent in the first place using the form but as I said I don't know how to redirect after the process is finish...
please help me
You can use some core Ruby libraries to make a subsequent request on the same endpoint to determine the status code of your request. Try the following, cited in whole from Ruby Inside:
# Basic REST.
# Most REST APIs will set semantic values in response.body and response.code.
require "net/http"
http = Net::HTTP.new("api.restsite.com")
request = Net::HTTP::Post.new("/users")
request.set_form_data({"users[login]" => "quentin"})
response = http.request(request)
# Use nokogiri, hpricot, etc to parse response.body.
request = Net::HTTP::Get.new("/users/1")
response = http.request(request)
# As with POST, the data is in response.body.
request = Net::HTTP::Put.new("/users/1")
request.set_form_data({"users[login]" => "changed"})
response = http.request(request)
request = Net::HTTP::Delete.new("/users/1")
response = http.request(request)
Once you've instantiated a response object, you can operate on it in the following manner:
response.code #=> returns HTTP response code