diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-18 19:31:14 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-18 19:31:14 +0800 |
commit | 1161463fce40f2e5b59ef6dd7406aa0a55f8d936 (patch) | |
tree | e22f3a5b71cec0e5229a55cf1b47908c55600d5b /pikul.c | |
parent | 98b431f3b0b1f45b9f05edc43fff19c586658445 (diff) | |
parent | 39190eb032cc6a8c2fe9d07ca85f712a229c0b69 (diff) |
Merge branch 'master' into sicepat
Diffstat (limited to 'pikul.c')
-rw-r--r-- | pikul.c | 60 |
1 files changed, 51 insertions, 9 deletions
@@ -3,15 +3,19 @@ CURL *curl; json_tokener *tokener; -static struct shipping shipping; +struct shipping shipping; -extern inline void headers(const char *[], char *[], struct shipping *); -extern inline void handle_services(const char *, size_t, const char *[], const char *[], const char *[], - struct pikul_services **); +void headers(const char *[], char *[]); +void handle(enum type, const char *, size_t, const char *[], const char *[], const char *[], void *); -extern void anteraja_init(char *[], struct shipping *); -extern void anteraja_services(const char *, const char *, double, struct shipping *, char **, char **); -extern size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); +void anteraja_init(char *[]); +void anteraja_services(const char *, const char *, double, char **, char **); +size_t anteraja_services_handle(const char *, size_t, size_t, struct pikul_services **); +void anteraja_order(const char *, const char *, const char *, const char *, const char *, const char *, + const char *, const char *, const char *, const char *, const char *, const char *, int, + char **[], double, char **, char **); +size_t anteraja_order_handle(const char *, size_t size, size_t nmemb, char **); +void anteraja_cleanup(); extern void sicepat_init(char *[], struct shipping *); extern void sicepat_services(const char *, const char *, double, struct shipping *, char **); @@ -27,7 +31,7 @@ void pikul_init(enum pikul_company company, char *provisions[]) shipping.company = company; switch (company) { case PIKUL_ANTERAJA: - anteraja_init(provisions, &shipping); + anteraja_init(provisions); break; case PIKUL_SICEPAT: sicepat_init(provisions, &shipping); @@ -58,7 +62,7 @@ struct pikul_services *pikul_services(const char *origin, const char *destinatio size_t (*handler)(const char *, size_t, size_t, struct pikul_services **); switch (shipping.company) { case PIKUL_ANTERAJA: - anteraja_services(origin, destination, weight, &shipping, &url, &post); + anteraja_services(origin, destination, weight, &url, &post); handler = anteraja_services_handle; break; case PIKUL_SICEPAT: @@ -117,8 +121,46 @@ double pikul_cost(const char *origin, const char *destination, double weight, co return cost; } +char *pikul_order(const char *order_number, const char *service, const char *sender_name, + const char *sender_phone, const char *origin, const char *sender_address, + const char *sender_postal, const char *receiver_name, const char *receiver_phone, + const char *destination, const char *receiver_address, const char *receiver_postal, + int nitems, char **items[], double subtotal) +{ + char *tracking_number = NULL; + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &tracking_number); + char *url; + char *post = NULL; + size_t (*handler)(const char *, size_t, size_t, char **); + switch (shipping.company) { + case PIKUL_ANTERAJA: + anteraja_order(order_number, service, sender_name, sender_phone, origin, + sender_address, sender_postal, receiver_name, receiver_phone, + destination, receiver_address, receiver_postal, nitems, items, + subtotal, &url, &post); + handler = anteraja_order_handle; + break; + default: + break; + } + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, handler); + curl_easy_perform(curl); + if (post) + free(post); + free(url); + return tracking_number; +} + void pikul_cleanup() { + switch (shipping.company) { + case PIKUL_ANTERAJA: + anteraja_cleanup(); + break; + default: + break; + } free(shipping.base); json_tokener_free(tokener); curl_slist_free_all(shipping.headers); |