From f6739e2e7cada25178bde2ef7921ba00a8a0fae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Wed, 5 Oct 2022 16:58:22 +0800 Subject: Test the status response --- midtrans.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'midtrans.c') 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() -- cgit v1.2.3