Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | wpinweb |
So maybe i am way off theme here, but i though i can ask the Godot Family. I want to implement payments in my godot app (exe) through PayPal. I am using HTTPRequests as a mean and follow the paypals documentation by step. Retrieving token is success, placing order is success but capturing order is fail (403) . I dont ask about a fix on this cause stackoverflow and paypal community exist for this purpose i guess…I am asking if any1 have used paypal integretion in past and can share some intelligence with me or if any1 can recommend a library for this purpose. I am (still) using GODOT 3.5. Again sorry if i am way off topic here.
func get_access_token():
var request = $HTTPRequest
var headers = PoolStringArray()
headers.append("Content-Type: application/x-www-form-urlencoded")
headers.append("Authorization: Basic " + client_id + ":" + client_secret)
headers.append("Accept-Language: en_US")
headers.append("Accept: application/json")
var body = "grant_type=client_credentials"
request.request(
"https://api-m.sandbox.paypal.com/v1/oauth2/token",
headers,
true,
HTTPClient.METHOD_POST,
body
)
request.connect("request_completed", self, "_on_access_token_response")
func paypal_process():
var request = $HTTPRequest2
var headers = PoolStringArray()
headers.append("Content-Type: application/json")
headers.append("Authorization: Bearer " + access_token)
headers.append("Accept: application/json")
var body = {
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": "EUR",
"value": "10.00"
}
}
]
}
request.request(
"https://api-m.sandbox.paypal.com/v2/checkout/orders",
headers,
true,
HTTPClient.METHOD_POST,
JSON.print(body)
)
request.connect("request_completed", self, "_on_paypal_response")
func get_order(order_id):
var request = $HTTPRequest3
var headers = PoolStringArray()
headers.append("Content-Type: application/json")
headers.append("Authorization: Bearer " + access_token)
headers.append("Accept: application/json")
request.request(
"https://api-m.sandbox.paypal.com/v2/checkout/orders/" + order_id + "/capture",
headers,
true,
HTTPClient.METHOD_POST
)
request.connect("request_completed", self, "_get_order_response")
Welcome to the community. While I don’t have an answer for you, your question seems entirely appropriate for the forum.
And, while I haven’t looked at PayPal’s API in a long time, using the HTTPRequest
object as the core of your solution seems like a good fit. That is, I think you should be able “to get there from here”…
Hopefully, someone will be able to provide more specific input.
Also, sharing some sample code might allow someone to spot the problem.
jgodfrey | 2023-05-11 20:03