summaryrefslogtreecommitdiff
path: root/midtrans.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <prabowo@darapsa.org>2022-10-05 16:58:22 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <prabowo@darapsa.org>2022-10-05 16:58:22 +0800
commitf6739e2e7cada25178bde2ef7921ba00a8a0fae2 (patch)
treef9be997a4def6c6e2ca987a50c4c3b6a2956c360 /midtrans.c
parent9ab0e1ae6dacbf9bc339cd8ec5b953c17113d242 (diff)
Test the status response
Diffstat (limited to 'midtrans.c')
-rw-r--r--midtrans.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/midtrans.c b/midtrans.c
index c51ce5b..ea0e175 100644
--- a/midtrans.c
+++ b/midtrans.c
@@ -54,6 +54,15 @@ void midtrans_init(_Bool production, const char *api_key, const char *cainfo)
curl_easy_setopt(curl, CURLOPT_CAINFO, cainfo);
}
+static size_t append(char *data, size_t size, size_t nmemb, char **res)
+{
+ size_t realsize = size * nmemb;
+ size_t res_len = *res ? strlen(*res) : 0;
+ *res = realloc(*res, res_len + realsize + 1);
+ strlcpy(&(*res)[res_len], data, realsize + 1);
+ return realsize;
+}
+
void midtrans_status(const char *order_id)
{
static const char *tmpl = "%s%s/status";
@@ -61,7 +70,17 @@ void midtrans_status(const char *order_id)
+ (sandbox ? strlen(ORDER_ID) : strlen(order_id)) + 1];
sprintf(url, tmpl, base_url, sandbox ? ORDER_ID : order_id);
curl_easy_setopt(curl, CURLOPT_URL, url);
+
+ char *res = NULL;
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
+
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append);
curl_easy_perform(curl);
+
+#ifdef DEBUG
+ printf("%s\n", res);
+#endif
+ free(res);
}
void midtrans_cleanup()