diff options
Diffstat (limited to 'StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js')
| -rw-r--r-- | StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js index fec5e1d1..f3c54d55 100644 --- a/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js +++ b/StoneIsland/platforms/ios/www/js/lib/cart/CartPayment.js @@ -2,13 +2,14 @@ var CartPayment = FormView.extend({ el: "#cart_payment", - address_template: $("#cart_payment .address_template").html(), + address_template: $("#cart_payment .address_row_template").html(), cc_template: $("#cart_payment .cc_template").html(), action: sdk.cart.set_credit_card, address_list_mode: false, cc_list_mode: false, + data: {}, events: { "change [name=SameAsShipping]": "toggle_shipping", @@ -28,6 +29,7 @@ var CartPayment = FormView.extend({ this.$cc_list = this.$(".cc_list") this.$cc_form = this.$(".cc") this.$cc_dropdown = this.$(".cc_dropdown") + this.$cc_confirm = this.$(".cc_confirm") this.address = new AddressView ({ parent: this, checkPhone: false }) this.cc = new CreditCardView ({ parent: this }) @@ -50,6 +52,7 @@ var CartPayment = FormView.extend({ setTimeout(function(){ var state = this.$same_as_shipping.prop("checked") this.$billing_address_rapper.toggle( ! state ) + this.address.disabled = state }.bind(this)) }, @@ -75,6 +78,7 @@ var CartPayment = FormView.extend({ this.cc.disabled = this.cc_list_mode this.$cc_form.toggle(! this.cc_list_mode) this.$cc_list.toggle(this.cc_list_mode) + this.$cc_confirm.toggle(this.cc_list_mode) }, populate: function(){ @@ -85,65 +89,94 @@ var CartPayment = FormView.extend({ this.toggle_cc( !! app.account.ccs.length ) app.account.ccs.forEach(function(cc){ - console.log(cc) - var address_t = this.address_template.replace(/{{id}}/g, cc.Id) .replace(/{{checked}}/g, cc.IsDefault ? "checked" : "") - .replace(/{{name}}/g, cc.Name + " " + cc.Surname) - .replace(/{{address}}/g, cc.Address.replace(/\n$/,"").replace("\n", "<br>")) + .replace(/{{name}}/g, (cc.Name + " " + cc.Surname).toUpperCase()) + .replace(/{{address}}/g, cc.Address.replace(/\n$/,"").replace("\n", ", ")) .replace(/{{city}}/g, cc.City) .replace(/{{state}}/g, cc.Province) .replace(/{{zip}}/g, cc.ZipCode) var cc_t = this.cc_template.replace(/{{id}}/g, cc.Id) .replace(/{{checked}}/g, cc.IsDefault ? "checked" : "") - .replace(/{{last4}}/g, cc.Last4) - .replace(/{{type}}/g, cc.Type) + .replace(/{{number}}/g, cc['Number']) + .replace(/{{type}}/g, cc.Type.toUpperCase()) .replace(/{{exp}}/g, cc.ExpirationMonth + "/" + cc.ExpirationYear) this.$address_list.append(address_t) this.$cc_list.append(cc_t) - }) + }.bind(this)) }, finalize: function(data){ - var shipping_info = {}, address_data, address_id, cc_info = {}, cc_data, cc_id + var shipping_info = {}, address_data, address_id, cc_info = {}, cc_data, cc_id var shipping_type = $("[name=ShippingType]").filter(function(){ return $(this).prop("checked") }).val() - if (this.list_mode) { - address_id = $("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val() + if (this.$same_as_shipping.prop("checked")) { + address_data = app.cart.shipping.data + } + else if (this.address_list_mode) { + address_id = this.$("[name=AddressId]").filter(function(){ return $(this).prop("checked") }).val() address_data = app.account.addressLookup[ address_id ] } else { address_data = data } + if (this.cc_list_mode) { - cc_id = $("[name=CCId]").filter(function(){ return $(this).prop("checked") }).val() + cc_id = this.$("[name=CCId]").filter(function(){ return $(this).prop("checked") }).val() cc_data = app.account.ccLookup[ cc_id ] + + var card_on_file = { + "guid": cc_data.Guid, + "cvv": this.$("[name=CvvConfirm]"), + } + + app.curtain.show("loading") + promise(sdk.cart.use_stored_credit_card, { data: card_on_file }).then(function(data){ + app.curtain.hide("loading") + this.success() + }.bind(this)).error(function(data){ + app.curtain.hide("loading") + console.log(data) + }.bind(this)) + + return } else { cc_data = data } - shipping_info.Name = address_data.Name - shipping_info.Surname = address_data.Surname - shipping_info.Email = auth.user.Email - shipping_info.Phone = address_data.Phone - shipping_info.Mobile = address_data.Phone - shipping_info.StreetWithNumber = address_data.Address - shipping_info.PostalCode = address_data.ZipCode - shipping_info.City = address_data.City - shipping_info.Province = address_data.Province - shipping_info.Region = address_data.Province - shipping_info.CountryCode = "US" + var credit_info = { + "HolderName": address_data.Name, + "HolderSurname": address_data.Surname, + "HolderAddress": address_data.Address || address_data.StreetWithNumber, + "HolderCity": address_data.City, + "HolderProvince": address_data.Province, + "HolderZip": address_data.PostalCode || address_data.ZipCode, + "HolderISOCountry": CANADIAN_LOOKUP[ address_data.Province ] ? "CA" : "US", + "HolderEmail": auth.user.Email, + "CardNumber": cc_data['Number'], + "Type": cc_data.Type, + "ExpirationMonth": cc_data.ExpirationMonth, + "ExpirationYear": cc_data.ExpirationYear.substr(2,3), + "Cvv": cc_data.Cvv, + } - return shipping_info + console.log( credit_info ) + + return credit_info }, success: function(){ app.router.go('cart/confirm') }, + error: function(data){ + console.log(data) + app.cart.payment.show_errors([["Number","There was a problem with your credit card."]]) + }, + cancel: function(){ app.router.go('cart/shipping') }, |
