Stripe Charge Card via HTTP Rest API - rest

I am attempting to charge a card via Stripe but am getting:
{ error:
{ type: 'invalid_request_error',
message: 'You must supply either a card or a customer id' } }
Below is in the body (assume api key is correctly in header, content type is application/x-www-form-urlencoded, it is a post request to https://api.stripe.com/v1/charges)
data = {
"amount": 400,
"currency": "usd",
"card": {
"number": "4242424242424242",
"exp_month": "12",
"exp_year": "2019",
"cvc": "442"
},
"description": "Charge for test#example.com"
}
Any idea why this isn't working? Is it formatted incorrectly? Can't find an example of doing it this way in Stripe Documentation. Can charging a card be done directly like this, or is a token required? If so, how can this be done via HTTP and not stripe.js?

Related

How to check whether whatsapp message is successfully sent or not in WA Business API?

Im sending whatsapp message from whatsapp business api. API collections i got from facebook-whatsapp docs. Link
My End goal to check blue tick, does recipient has seen the message.
When you call the send message endpoint (POST /v1/messages), if it succeeds (201 created), you will receive a message ID on the return payload (e.g. 12345), like this:
{
"messages": [{
"id": "12345"
}]
}
After that, at some in the future, whatsapp will asynchronously send notifications to the webhook server informing every status changes on that message (sent, delivered, read, failed and deleted). That notifications will be referencing that same message ID informed before (e.g. 12345), like this:
{
"statuses": [{
"id": "",
"recipient_id": "553199999999",
"status": "delivered",
"timestamp": "1650509418",
"type": "message",
"conversation": {
...
},
"pricing": {
...
}
}]
}
(Check https://developers.facebook.com/docs/whatsapp/on-premises/webhooks/outbound for more details).
So, if you need to ensure a message was read, you must capture that sent message ID and then observe all the status change notifications until you receive the proper read status for that very message, with that specific id.

When `actions.intent.TRANSACTION_REQUIREMENTS_CHECK` returns result different than `OK`?

I want to create a chatbot with Dialogflow and Google Assistant along with Google Transactions API for enabling a user to order a chocolate box. For now my agent contains the following four intents:
Default Welcome Intent (text response: Hello, do you want to buy a chocolate box?)
Default Fallback Intent
Int1 (training phrase: Yes, I want, fulfilment: enabled webhook call)
Int2 (event: actions_intent_TRANSACTION_REQUIREMENTS_CHECK )
I am using Dialogflow Json instead of Node.js to connect my agent with Transactions API. I want to test that the user meets the transaction requirements (when ordering the chocolate box) by using the actions.intent.TRANSACTION_REQUIREMENTS_CHECK action of Google actions. For this reason, following Google docs, when Int1 is triggered I am using a webhook which connects Google Assistant to the following python script (back-end):
from flask import Flask, render_template, request, jsonify
from flask_cors import CORS
import requests
app = Flask(__name__)
CORS(app)
#app.route("/", methods=['POST'])
def index():
data = request.get_json()
intent = data["queryResult"]["intent"]["displayName"]
if (intent == 'Int1'):
return jsonify({ "data": {
"google": {
"expectUserResponse": True,
"isSsml": False,
"noInputPrompts": [],
"systemIntent": {
"data": {
"#type": "type.googleapis.com/google.actions.v2.TransactionRequirementsCheckSpec",
"paymentOptions": {
"actionProvidedOptions": {
"displayName": "VISA-1234",
"paymentType": "PAYMENT_CARD"
}
}
},
"intent": "actions.intent.TRANSACTION_REQUIREMENTS_CHECK"
}
}
}
})
else:
return jsonify({'message': 'HERE'})
if __name__== "__main__":
app.run(debug=True)
The result in the json response which I receive after actions.intent.TRANSACTION_REQUIREMENTS_CHECK and Int2 are triggered is:
"arguments": [
{
"extension": {
"#type": "type.googleapis.com/google.actions.v2.TransactionRequirementsCheckResult",
"resultType": "OK"
},
"name": "TRANSACTION_REQUIREMENTS_CHECK_RESULT"
}
]
The confusing fact is that even if I send:
{
"displayName": "FALSE",
"paymentType": "PAYMENT_CARD"
}
the response is the same which means that it returns again OK.
When I send something like this
{
"displayName": "FALSE",
"paymentType": "WRONG"
}
then I get an error:
API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "(payment_options.action_provided_options.payment_type): invalid value "WRONG" for type TYPE_ENUM".
but this is not exactly given by actions.intent.TRANSACTION_REQUIREMENTS_CHECK and Int2 because these two are not triggered so I do not get any json response back with a result different than OK.
Therefore, my question is: In which cases am I going to receive a result from actions.intent.TRANSACTION_REQUIREMENTS_CHECK which is different than OK?
If I am going to get an OK result for anything that I am writing then what is the point of using actions.intent.TRANSACTION_REQUIREMENTS_CHECK?
P.S.
I have in mind the following about actions.intent.TRANSACTION_REQUIREMENTS_CHECK from Google docs:
Note: The actions.intent.TRANSACTION_REQUIREMENTS_CHECK intent is
currently under development and will return a success state regardless
of the user's payment settings and locale. To test out the failure
state scenario, request the intent on a voice-activated speaker.
but still I am not seeing any difference when I using this app on Google Assistant with my voice on my mobile phone.
I think that you we have to return to Google docs to solve this. According to Google docs the possible responses of actions.intent.TRANSACTION_REQUIREMENTS_CHECK are the following: RESULT_TYPE_UNSPECIFIED, OK, USER_ACTION_REQUIRED, ASSISTANT_SURFACE_NOT_SUPPORTED, REGION_NOT_SUPPORTED
(image).
Nothing of them has to do exactly with this:
"paymentOptions": {
"actionProvidedOptions": {
"displayName": "VISA-1234",
"paymentType": "PAYMENT_CARD"
}
}
This is also because your back-end cannot (or it is not even allowed to) directly reach the payment details of the user so the json above is only inserted by your back-end if you know them or in a sense you can write whatever you want. This is only for being displayed at the order preview and it is not cross-checked with the payment details of the user's Google account.
In conclusion, actions.intent.TRANSACTION_REQUIREMENTS_CHECK may only return a non OK status if the result is unspecified (RESULT_TYPE_UNSPECIFIED) or if the user is expected to take action (USER_ACTION_REQUIRED) or if the transactions are not supported on current device/surface (ASSISTANT_SURFACE_NOT_SUPPORTED) or if the transactions are not supported for current region/country (REGION_NOT_SUPPORTED).

Paypal error message "Capture amount exceeds allowable limit"

We wrote the below function in sandbox environment
function captureTransactions(access_token, d) {
try {
var req = http.request("POST", _config.host + "/v1/payments/authorization/" + d.authorization_id + "/capture", JSON.stringify({
"amount": {
"currency": "USD",
"total": d.total
},
"is_final_capture": true
}), {
"Content-Type": "application/json",
"Authorization": "Bearer " + access_token
});
var r = JSON.parse(req.readAll().toString());
} catch (e) {
console.error(e.stack);
console.error(r);
}
console.warn("[captureTransactions]", r);
return r;
};
and receive the below error
{
"name": "CAPTURE_AMOUNT_LIMIT_EXCEEDED",
"message": "Capture amount exceeds allowable limit.",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#CAPTURE_AMOUNT_LIMIT_EXCEEDED",
"debug_id": "2fc79fc7df623"
}
Can anyone tell me what is the reason for receiving this msg and how to fix it? Note that we only test $5 payments so it shouldn't be due to transaction size. We did do multiple authorizations on the same card before, but not sure if that could be the reason for this error?
Appreciate your help!
I have had this problem on the live site with PayFlow today. It appears that you cannot use a "Credit Card" that is "Attached" to that "Gateway" account with "PayPal".
I supposed that is a method to stop "Customers" (PayPal payment service users) from "Paying" themselves as a Paypal employee explained to me on another separate issue. That is where we were testing a Billing Software with the gateway and refunding the money back to our account after the transaction. We were told that we could put our own money into our account(s) that way. At the time "I ask how we were to pay the $60.00 monthly fee if the business (PayPal account) hasn't collected/processed any money yet if we can't put money in there? This was resolved by the 1st part of this Answer.

Can't post node that requires a pre assigned value with services api

I have setup a content type with a subject field that has pre assigned values in a dropdown field.
I am using the services api to post new content from a polymer app.
When I POST to the api I send the field structure and value in json but get and error.
"406 (Not Acceptable : An illegal choice has been detected. Please contact the site administrator.)"
Even though the object I am sending matches one of the required values in the field.
Do I need to prefix the value with something? I assume I'm posting to the right place to get that response but don't know why it would accept anything other than the string value.
Here is what I sent to the api which is picked up by my Charles proxy.
{
"node": {
"type": "case",
"title": "my case",
"language": "und",
"field_subject": {
"und": {
"0": {
"value": "subject1"
}
}
},
"body": {
"und": {
"0": {
"value": "my details of subject"
}
}
}
}
}
And here is an example of what I have setup in my Drupal field
subject1| first
subject2| second
subject3| third
subject4| forth
For anyone else with the same problem, this subject is poorly documented, but the answer is simple, my subject did not need the value key despite devel suggesting thats how it would be formatted.
"field_subject": {
"und": [
"subject1"
]
}
I could also shorten my code with "und" being an array.

Pay with Paypal through Paypal REST API does not show up payment description on Paypal Sandbox or live sites

I am implementing Paypal's new REST API Pay with Paypal method that can be referenced here:
https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/
The payment executes fine, exactly the way it should be. The user chooses to pay with Paypal and is then redirected to the Paypal site where he is expected to log in and approve the payment. The JSON data that I am sending Paypal is pretty much what is specified in the above link and mine looks like this:
{
"intent":"sale",
"redirect_urls":{
"return_url":"http://<return URL here>",
"cancel_url":"http://<cancel URL here>"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment description."
}
]
}
As it redirects the user to the paypal website, the description and total amount column is shown blank
I am not sure if this is a mistake on Paypal's REST API but I believe I am providing the necessary description + amount payment to be reflected on this page. If this information is not shown, it is typically a deterrent to the user since they would definitely like to see the amount they are paying on the Paypal site even though this amount is listed on my website.
This is what it looks like:
For those who would like to indicate that the user has not logged in, well, even after logging in, the description and the current purchase column remain blank.
Am I missing any parameters that need to be sent to Paypal in order to indicate this description data?
Note: This issue persists for both the live and sandbox servers.
The left hand pan in above page displays:
1. Item details from order. You can include item list as part of the transaction details in payment resource. The same will be displayed here.
2. Components of the transaction amount e.g. shipping amount, tax, etc. if you include them in request.
Try this request to see example:
{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://<return url>",
"cancel_url": "http://<cancle url>"
},
"transactions": [
{
"amount": {
"total": "8.00",
"currency": "USD",
"details": {
"subtotal": "6.00",
"tax": "1.00",
"shipping": "1.00"
}
},
"description": "This is payment description.",
"item_list": {
"items":[
{
"quantity":"3",
"name":"Hat",
"price":"2.00",
"sku":"product12345",
"currency":"USD"
}
]
}
}
]
}
Thank you. Madhu remember to use the rest-api library!
Details amountDetails = new Details();
amountDetails.setSubtotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
amountDetails.setTax("0");
amountDetails.setShipping("0");
Amount amount = new Amount();
amount.setCurrency("USD");
amount.setTotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
// amount.setTotal("7.47"); // Los decimales deben ser con punto
amount.setDetails(amountDetails);
Item item = new Item();
item.setCurrency("USD");
item.setQuantity("1");
item.setName(autoregistro.getPedido().getItems().get(0).getDescripcion());
item.setPrice(amountDetails.getSubtotal());
List<Item> items = new ArrayList<Item>();
items.add(item);
ItemList itemList = new ItemList();
itemList.setItems(items);
Transaction transaction = new Transaction();
transaction.setDescription(item.getName());
transaction.setAmount(amount);
transaction.setItemList(itemList);
List<Transaction> transactions = new ArrayList<Transaction>();
transactions.add(transaction);
Payer payer = new Payer();
payer.setPaymentMethod("paypal");
// payer.setPaymentMethod("credit_card");
Payment payment = new Payment();
payment.setIntent("sale");
payment.setPayer(payer);
payment.setTransactions(transactions);
RedirectUrls redirectUrls = new RedirectUrls();
redirectUrls.setCancelUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?cancel=true");
redirectUrls.setReturnUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?success=true");
payment.setRedirectUrls(redirectUrls);
Payment createdPayment = payment.create(apiContext);