Hi, I couldn't get the API v2 working, does it need an input json object to post a transaction:
{
"card_brand": "VISA",
"last_4": "1111",
"exp_month": 11,
"exp_year": 2016,
"billing_postal_code": "94103"
}
I found an example to generate the input/json, but it doesn't work, what scripting language it is?
var paymentForm = new SqPaymentForm({
applicationId: '', // <-- REQUIRED: Add Application ID
inputClass: 'sq-input',
inputStyles: [
{
fontSize: '15px'
}
],
cardNumber: {
elementId: 'sq-card-number',
placeholder: '•••• •••• •••• ••••'
},
cvv: {
elementId: 'sq-cvv',
placeholder: 'CVV'
},
expirationDate: {
elementId: 'sq-expiration-date',
placeholder: 'MM/YY'
},
...
Also when I try to access v2 api using java/okhttp( I am sure I added headers), but it always tells me:
{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"Au
thorization in header is required"}]}
Here is my code:
String doPostRequest(String url, String json) throws IOException {
RequestBody body = RequestBody.create(JSON, json);
Request request = new Request.Builder().url(url)
.header("Authorization", "Bearer " + sandbox_access_token).addHeader("Content-Type", "application/json").addHeader("Accept", "application/json").post(body).build();
Headers requestHeaders = request.headers();
for (int i = 0; i < requestHeaders.size(); i++) {
System.out.println(requestHeaders.name(i) + ": " + requestHeaders.value(i));
}
//request.addHeader("Authorization", "Bearer " + access_token);
//request.addHeader("Accept", "application/json");
Response response = client.newCall(request).execute();
//System.out.println("response:" + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + "; " + responseHeaders.value(i));
}
return response.body().string();
}
Thanks!
Anne
Hello @Anne! I'll run this by our developer team and we'll circle back with an update ASAP. Thanks for your patience. 🙂
Hey @Anne, regarding:
I found an example to generate the input/json, but it doesn't work, what scripting language it is?
This example is JavaScript that is meant to be run in the browser. It's meant to construct the payment form that allows customers to input their card details. Here are instructions for getting this set up: embedding the payment form.
Hope this helps. Please let me know if anything else comes up!
Hi @Anne, the Connect V2 APIs require the use of https. The same issue could occur if non-secure http protocol is used. Could you try the code again with the https protocol if it was using http?
Square Community