diff options
-rw-r--r-- | icclient/member.h | 7 | ||||
-rw-r--r-- | icclient/ord.h | 3 | ||||
-rw-r--r-- | ord.c | 77 |
3 files changed, 86 insertions, 1 deletions
diff --git a/icclient/member.h b/icclient/member.h index d68f814..0f4ac22 100644 --- a/icclient/member.h +++ b/icclient/member.h @@ -1,6 +1,11 @@ #ifndef ICCLIENT_MEMBER_H #define ICCLIENT_MEMBER_H +struct icclient_member_preferences { + bool mv_same_billing; + bool email_copy; +}; + struct icclient_member { char *username; char *usernick; @@ -39,7 +44,7 @@ struct icclient_member { char *phone_night; char *address_book; char *accounts; - char *preferences; + struct icclient_member_preferences *preferences; char *carts; char *owner; char *file_acl; diff --git a/icclient/ord.h b/icclient/ord.h index 5195e81..a1dd4ea 100644 --- a/icclient/ord.h +++ b/icclient/ord.h @@ -10,6 +10,7 @@ struct icclient_ord_order { double subtotal; double shipping; double total_cost; + char *profile; size_t nitems; struct icclient_ord_item *items[]; }; @@ -27,6 +28,8 @@ extern "C" { */ void icclient_ord_order(const char *sku, const struct icclient_catalog *catalog, struct icclient_ord_order **orderptr); + void icclient_ord_checkout(struct icclient_ord_order *order, + struct icclient_member *member); void icclient_ord_free(struct icclient_ord_order *order); #ifdef __cplusplus @@ -3,6 +3,7 @@ #include "request.h" #include "icclient/catalog.h" #include "icclient/product.h" +#include "icclient/member.h" #include "icclient/ord.h" typedef struct icclient_catalog icclient_catalog; @@ -83,6 +84,82 @@ void icclient_ord_order(const char *sku, const icclient_catalog *catalog, request(NULL, NULL, NULL, "%s%s", "order?mv_arg=", sku); } +void icclient_ord_checkout(struct icclient_ord_order *order, + struct icclient_member *member) +{ + struct curl_httppost *post, *last = NULL; + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "mv_todo", + CURLFORM_COPYCONTENTS, "submit", + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "mv_action", + CURLFORM_COPYCONTENTS, "refresh", + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "mv_order_profile", + CURLFORM_PTRCONTENTS, order->profile, + CURLFORM_END); + if (member->fname) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "fname", + CURLFORM_PTRCONTENTS, member->fname, + CURLFORM_END); + if (member->lname) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "lname", + CURLFORM_PTRCONTENTS, member->lname, + CURLFORM_END); + if (member->address1) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "address1", + CURLFORM_PTRCONTENTS, member->address1, + CURLFORM_END); + if (member->address2) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "address2", + CURLFORM_PTRCONTENTS, member->address2, + CURLFORM_END); + if (member->city) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "city", + CURLFORM_PTRCONTENTS, member->city, + CURLFORM_END); + if (member->state) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "state", + CURLFORM_PTRCONTENTS, member->state, + CURLFORM_END); + if (member->zip) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "zip", + CURLFORM_PTRCONTENTS, member->zip, + CURLFORM_END); + if (member->email) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "email", + CURLFORM_PTRCONTENTS, member->email, + CURLFORM_END); + if (member->phone_day) + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "phone_day", + CURLFORM_PTRCONTENTS, member->phone_day, + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "mv_same_billing", + CURLFORM_COPYCONTENTS, + member->preferences->mv_same_billing? "1" : "0", + CURLFORM_END); + curl_formadd(&post, &last, + CURLFORM_COPYNAME, "email_copy", + CURLFORM_COPYCONTENTS, member->preferences->email_copy? "1" : "0", + CURLFORM_END); + last = NULL; + request(NULL, NULL, post, "%s", "ord/checkout"); + curl_formfree(post); + post = NULL; +} + void icclient_ord_free(struct icclient_ord_order *order) { for (size_t i = 0; i < order->nitems; i++) |