public StorageReceipt addToStorage(String storageTokenId, PaymentProfile paymentProfile)
 {
     if (paymentProfile == null) {
         return new StorageReceipt(REQ_INVALID_REQUEST,
             "paymentProfile is required", null);
     }
     // create the request string
     StringBuilder req = new StringBuilder();
     try {
         this.appendHeader(req, "secureStorage");
         this.appendOperationType(req, "create");
         this.appendStorageTokenId(req, storageTokenId);
         this.appendPaymentProfile(req, paymentProfile);
     } catch (Exception e) {
         return new StorageReceipt(REQ_INVALID_REQUEST, e.ToString(), null);
     }
     return this.sendStorageRequest(req);
 }
 public StorageReceipt(String response)
     : base(response)
 {
     // storage token ID
     this.storageTokenId = (String) this.responseParams["STORAGE_TOKEN_ID"];
     // make sure profile available
     bool paymentProfileAvailable = this
         .parseBoolean("PAYMENT_PROFILE_AVAILABLE");
     if (paymentProfileAvailable) {
         // parse the CreditCard
         CreditCard creditCard = null;
         bool creditCardAvailable = this.parseBoolean("CREDIT_CARD_AVAILABLE");
         if (creditCardAvailable) {
             String sanitized = (String) this.responseParams["CREDIT_CARD_NUMBER"];
             sanitized = sanitized.Replace("*", "");
             creditCard = new CreditCard(long.Parse(sanitized), this.parseShort("EXPIRY_DATE"));
         }
         // parse the Customer Profile
         CustomerProfile profile = null;
         bool customerProfileAvailable = this.parseBoolean("CUSTOMER_PROFILE_AVAILABLE");
         if (customerProfileAvailable) {
             profile = new CustomerProfile();
             profile.setLegalName((String)this.responseParams["CUSTOMER_PROFILE_LEGAL_NAME"]);
             profile.setTradeName((String)this.responseParams["CUSTOMER_PROFILE_TRADE_NAME"]);
             profile.setWebsite((String)this.responseParams["CUSTOMER_PROFILE_WEBSITE"]);
             profile.setFirstName((String)this.responseParams["CUSTOMER_PROFILE_FIRST_NAME"]);
             profile.setLastName((String)this.responseParams["CUSTOMER_PROFILE_LAST_NAME"]);
             profile.setPhoneNumber((String)this.responseParams["CUSTOMER_PROFILE_PHONE_NUMBER"]);
             profile.setFaxNumber((String)this.responseParams["CUSTOMER_PROFILE_FAX_NUMBER"]);
             profile.setAddress1((String)this.responseParams["CUSTOMER_PROFILE_ADDRESS1"]);
             profile.setAddress2((String)this.responseParams["CUSTOMER_PROFILE_ADDRESS2"]);
             profile.setCity((String)this.responseParams["CUSTOMER_PROFILE_CITY"]);
             profile.setProvince((String)this.responseParams["CUSTOMER_PROFILE_PROVINCE"]);
             profile.setPostal((String)this.responseParams["CUSTOMER_PROFILE_POSTAL"]);
             profile.setCountry((String)this.responseParams["CUSTOMER_PROFILE_COUNTRY"]);
         }
         this.paymentProfile = new PaymentProfile(creditCard, profile);
     } else {
         this.paymentProfile = null;
     }
 }
 private void appendPaymentProfile(StringBuilder req, PaymentProfile paymentProfile)
 {
     if (paymentProfile == null) {
         return;
     } else {
         if (paymentProfile.getCreditCard() != null) {
             this.appendCreditCard(req, paymentProfile.getCreditCard());
         }
         if (paymentProfile.getCustomerProfile() != null) {
             this.appendParam(req, "profileLegalName", paymentProfile.getCustomerProfile().getLegalName());
             this.appendParam(req, "profileTradeName", paymentProfile.getCustomerProfile().getTradeName());
             this.appendParam(req, "profileWebsite", paymentProfile.getCustomerProfile().getWebsite());
             this.appendParam(req, "profileFirstName", paymentProfile.getCustomerProfile().getFirstName());
             this.appendParam(req, "profileLastName", paymentProfile.getCustomerProfile().getLastName());
             this.appendParam(req, "profilePhoneNumber", paymentProfile.getCustomerProfile().getPhoneNumber());
             this.appendParam(req, "profileFaxNumber", paymentProfile.getCustomerProfile().getFaxNumber());
             this.appendParam(req, "profileAddress1", paymentProfile.getCustomerProfile().getAddress1());
             this.appendParam(req, "profileAddress2", paymentProfile.getCustomerProfile().getAddress2());
             this.appendParam(req, "profileCity", paymentProfile.getCustomerProfile().getCity());
             this.appendParam(req, "profileProvince", paymentProfile.getCustomerProfile().getProvince());
             this.appendParam(req, "profilePostal", paymentProfile.getCustomerProfile().getPostal());
             this.appendParam(req, "profileCountry", paymentProfile.getCustomerProfile().getCountry());
         }
     }
 }
    public static void Main(string [] args)
    {
        int merchantId=0;
        string apiToken="";
        string url="";

        long pan = 0;
        short expiry = 0;

        String firstName = null;
        String lastName = null;

        string storageTokenId = "";
        string orderId = "";
        long amount = 0;

        string method="";

        if(args.Length >=5){
            method=args[0];
            url=args[1];
            merchantId = Convert.ToInt32(args[2]);
            apiToken=args[3];
            storageTokenId = args[4];
            if(method.Equals("add")){
                pan = Convert.ToInt64(args[5]);
                expiry = Convert.ToInt16(args[6]);
                firstName = args[7];
                lastName = args[8];
            }
            else if(method.Equals("delete")) {
            }
            else if (method.Equals("query")) {
            }
            else if (method.Equals("update"))
            {
                pan = Convert.ToInt64(args[5]);
                expiry = Convert.ToInt16(args[6]);
                firstName = args[7];
                lastName = args[8];
            } else if (method.Equals("purchase")) {
                orderId = args[5];
                amount = Convert.ToInt64(args[6]);
            }
            System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();

            // Service
            HttpsCreditCardService ccService = new HttpsCreditCardService(merchantId, apiToken, url);
            AbstractReceipt resp=null;
            // invoke txn method
            if(method.Equals("add")){
                CreditCard creditCard = new CreditCard(pan, expiry);
                CustomerProfile customerProfile = new CustomerProfile();
                customerProfile.setFirstName(firstName);
                customerProfile.setLastName(lastName);
                PaymentProfile paymentProfile = new PaymentProfile(creditCard, customerProfile);
                Console.WriteLine("made profile");
                resp = ccService.addToStorage(storageTokenId, paymentProfile);
                Console.WriteLine("got resp");
            } else if (method.Equals("delete")){
                resp = ccService.deleteFromStorage(storageTokenId);
            } else if (method.Equals("query")) {
                resp = ccService.queryStorage(storageTokenId);
            } else if (method.Equals("update")){
                CreditCard creditCard = new CreditCard(pan, expiry);
                CustomerProfile customerProfile = new CustomerProfile();
                customerProfile.setFirstName(firstName);
                customerProfile.setLastName(lastName);
                PaymentProfile paymentProfile = new PaymentProfile(creditCard, customerProfile);
                resp = ccService.updateStorage(storageTokenId, paymentProfile);
            } else if (method.Equals("purchase")){
                resp = ccService.singlePurchase(orderId, storageTokenId, amount, null);
            } else  {
                Console.WriteLine("args[0] must be add, delete, query, update, or purchase");
            }
            if(resp.isApproved()){
                Console.WriteLine("Response: {0}", resp.ToString());
            } else {
                //display error
                Console.WriteLine("isApproved: {0}", resp.isApproved());
                Console.WriteLine("Error Code: {0} Message: {1}",resp.getErrorCode(),resp.getErrorMessage());
            }
        } else {
            Console.WriteLine("[Invalid Command]");
            Console.WriteLine("");
            Console.WriteLine("Usage:");
            Console.WriteLine("");
            Console.WriteLine("Add: add url(string) merchantId(int) apiToken(string) storageTokenId(string) pan(long) expiry(short) firstName(string) lastName(string)");
            Console.WriteLine("      StorageGatewayTest add https://test.admeris.com/ccgateway/cc/processor.do 6 abcdefgh myStorageToken 4242424242424242 1210 John Smith");
            Console.WriteLine("------------------------------------*---------------------------------------");
            Console.WriteLine("Delete: delete url(string) merchantId(int) apiToken(string) storageTokenId(string)");
            Console.WriteLine("      StorageGatewayTest delete https://test.admeris.com/ccgateway/cc/processor.do 6 abcdefgh myStorageToken");
            Console.WriteLine("------------------------------------*---------------------------------------");
            Console.WriteLine("Query: query url(string) merchantId(int) apiToken(string) storageTokenId(string)");
            Console.WriteLine("      StorageGatewayTest query https://test.admeris.com/ccgateway/cc/processor.do 6 abcdefgh myStorageToken");
            Console.WriteLine("------------------------------------*---------------------------------------");
            Console.WriteLine("Update: update url(string) merchantId(int) apiToken(string) storageTokenId(string) expiry(short) firstName(string) lastName(string)");
            Console.WriteLine("      StorageGatewayTest update https://test.admeris.com/ccgateway/cc/processor.do 6 abcdefgh myStorageToken 4111111111111111 1111 Jane Doe");
            Console.WriteLine("------------------------------------*---------------------------------------");
            Console.WriteLine("Purchase: purchase url(string) merchantId(int) apiToken(string) storageTokenId(string) order_id(string) amount_in_cents(long) ");
            Console.WriteLine("      StorageGatewayTest purchase https://test.admeris.com/ccgateway/cc/processor.do 6 abcdefgh myStorageToken order-001 100");
        }
    }