Fix urldecoding on stripe side
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <pcrecpp.h>
|
||||
#include <json-c/json.h>
|
||||
@@ -686,6 +689,14 @@ long stripe_create_customer_parse(char *json, char *id, size_t id_size)
|
||||
return res;
|
||||
}
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = str.find(from);
|
||||
if(start_pos == std::string::npos)
|
||||
return false;
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
curl https://api.stripe.com/v1/customers \
|
||||
-u sk_test_MJYII1vrGGr7RrGw1lhYMiTq: \
|
||||
@@ -712,9 +723,13 @@ long stripe_create_customer(const char *key, char *token, const char *email, con
|
||||
|
||||
if(curl) {
|
||||
bzero(post_fields, sizeof(post_fields));
|
||||
// Patch email
|
||||
std::string patched_email = email;
|
||||
replace(patched_email, "+", "%2B"); // replace all '+' to '%2B' to avoid "urldecoding" on strip side
|
||||
|
||||
snprintf(post_fields, sizeof(post_fields),
|
||||
"email=%s&description=%s&metadata[customer_id]=%s&source=%s",
|
||||
email, description, metadata, token);
|
||||
patched_email.c_str(), description, metadata, token);
|
||||
|
||||
/* Now specify the POST data */
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_fields);
|
||||
|
||||
Reference in New Issue
Block a user