summaryrefslogtreecommitdiff
path: root/anteraja.c
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-16 22:32:55 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-16 22:32:55 +0800
commit6960f565208af11828920f262d201e9db7a9aba4 (patch)
tree38f2e5d3519a160050b573b186223a181b152ac1 /anteraja.c
parent3500f0a5cd000ff0d650ab716f92a35dcf1c1581 (diff)
parcel_total_weight turns out to be required
We use Interchange as a reference, and the unit weight is not saved to database for the transaction, only shipping cost. So to make it convenient for the library users, the total weight calculation is done by the library, so no need to pass any total weight argument.
Diffstat (limited to 'anteraja.c')
-rw-r--r--anteraja.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/anteraja.c b/anteraja.c
index c64ac68..8b78815 100644
--- a/anteraja.c
+++ b/anteraja.c
@@ -15,6 +15,7 @@
"{\
\"booking_id\":\"%s-%s\",\
\"service_code\":\"%s\",\
+\"parcel_total_weight\":%d,\
\"shipper\":{\
\"name\":\"%s\",\
\"phone\":\"%s\",\
@@ -32,6 +33,7 @@
],\
\"declared_value\":%d\
}"
+#define ORDER_WEIGHT 5
#define ORDER_SUBTOTAL 9
#define ORDER_ITEM \
@@ -100,13 +102,18 @@ void anteraja_order(const char *trx_id, const char *service, const char *sender_
sprintf(*url, "%s%s", shipping.base, ORDER_PATH);
enum { SKU, QUANTITY, DESCRIPTION, PRICE, WEIGHT };
char *json = NULL;
+ double total_weight = 0;
for (int i = 0; i < nitems; i++) {
size_t length = strlen(ORDER_ITEM) + strlen(items[i][DESCRIPTION]) + ORDER_ITEM_QUANTITY
+ ORDER_ITEM_PRICE + ORDER_ITEM_WEIGHT - strlen("%s") - 3 * strlen("%d")
+ strlen(",");
char item[length + 1];
+ double weight = atof(items[i][WEIGHT]) * 1000.0;
+ if (weight < 100.0)
+ weight = 100.0;
sprintf(item, ORDER_ITEM, items[i][DESCRIPTION], atoi(items[i][QUANTITY]),
- atoi(items[i][PRICE]), atoi(items[i][WEIGHT]) * 1000);
+ atoi(items[i][PRICE]), (int)weight);
+ total_weight += weight;
if (json)
json = realloc(json, strlen(json) + length + 1);
else {
@@ -120,13 +127,13 @@ void anteraja_order(const char *trx_id, const char *service, const char *sender_
json[strlen(json)] = '\0';
}
*post = malloc(strlen(ORDER_POST) + strlen(prefix) + strlen(trx_id) + strlen(service)
- + strlen(sender_name) + strlen(sender_phone) + strlen(origin)
+ + ORDER_WEIGHT + strlen(sender_name) + strlen(sender_phone) + strlen(origin)
+ strlen(sender_address) + strlen(receiver_name) + strlen(receiver_phone)
+ strlen(destination) + strlen(receiver_address) + strlen(json) + ORDER_SUBTOTAL
- - 12 * strlen("%s") - strlen("%d") + 1);
- sprintf(*post, ORDER_POST, prefix, trx_id, service, sender_name, sender_phone, origin,
- sender_address, receiver_name, receiver_phone, destination, receiver_address, json,
- (int)subtotal);
+ - 12 * strlen("%s") - 2 * strlen("%d") + 1);
+ sprintf(*post, ORDER_POST, prefix, trx_id, service, (int)total_weight, sender_name, sender_phone,
+ origin, sender_address, receiver_name, receiver_phone, destination,
+ receiver_address, json, (int)subtotal);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, *post);
}