#include <stdio.h>
#include <stdlib.h>
#include <atmi.h>
#include <ubf.h>
#include "acq.fd.h"

int main(int argc, char **argv)
{
    if (tpinit(NULL) < 0) { fprintf(stderr, "tpinit FAIL: %s\n", tpstrerror(tperrno)); return 1; }

    UBFH *b = (UBFH *)tpalloc("UBF", NULL, 1024);
    long amount = 1000000;   /* 10,000.00원 */
    Bchg(b, T_MERCHANT, 0, "M0001", 0L);
    Bchg(b, T_AMOUNT, 0, (char *)&amount, 0L);

    long rlen = 0;
    if (tpcall("ACQUIRE", (char *)b, 0L, (char **)&b, &rlen, 0L) < 0) {
        fprintf(stderr, "tpcall FAIL: %s\n", tpstrerror(tperrno));
        return 1;
    }

    long fee = 0, net = 0; char st[32] = ""; BFLDLEN l = sizeof(st);
    Bget(b, T_FEE, 0, (char *)&fee, 0L);
    Bget(b, T_NET, 0, (char *)&net, 0L);
    Bget(b, T_STATUS, 0, st, &l);
    printf(">>> TPCALL OK: amount=%ld fee=%ld net=%ld status=%s\n", amount, fee, net, st);

    tpfree((char *)b); tpterm();
    return 0;
}
