caboose-cms 0.8.62 → 0.8.63

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4106e491d93b523834ee2666e8b56318619b105
4
- data.tar.gz: ed68ff328ca5bd231ebec43547d03135e17582ca
3
+ metadata.gz: 29bfd5e0f0743f4775004a3f59719900efc517f4
4
+ data.tar.gz: 459868d31674a46f4eff2f8bbf2f0ea962028789
5
5
  SHA512:
6
- metadata.gz: 958a0609222e9d01efcdfb5c56de683cd193063df59d01cf3ce1e02df3f8efe74fcaf8d0d7d02525d87c10cdb59061653d1e106102f4bfa50b222bf1938e7601
7
- data.tar.gz: 2529ba70074ed38ad461ab05ac478c0cdd4c1b95a74748a1cdf3ac3239df88f7accce80e6b5e402f5b12189ee5309384835102bc29c9b86799cf155857e3fb0a
6
+ metadata.gz: 9415b36ed339e43501767cbb4d991890eb1809ce1cf173d43d79e2d393d379c870191e1533cbf4eb6ea2b1e65902659c5959116bfcff80efc231c19892481a7d
7
+ data.tar.gz: 7306430f0dbcf7d6331d2ffa0c7b22669a3f6f62a726f71fc2fc8a3de6711e11db5d80851510ca0c83429ea620eccc507e4c676b9d4e33182400efc31212124a
@@ -717,7 +717,7 @@ InvoiceController.prototype = {
717
717
  summary_table: function(table)
718
718
  {
719
719
  var that = this;
720
- var requires_shipping = that.invoice_requires_shipping();
720
+ var requires_shipping = that.invoice_requires_shipping();
721
721
  if (that.invoice.line_items.length > 0 || that.invoice.invoice_packages.length > 0)
722
722
  {
723
723
  table.append($('<tr/>').append($('<th/>').attr('colspan', requires_shipping ? '6' : '5').html('&nbsp;')));
@@ -938,11 +938,12 @@ InvoiceController.prototype = {
938
938
  capture_transaction: function(transaction_id, confirm)
939
939
  {
940
940
  var that = this;
941
- var t = that.transaction_with_id(transaction_id);
941
+ var t = that.transaction_with_id(transaction_id);
942
+ var amount = that.invoice.total < t.amount ? that.invoice.total : t.amount;
942
943
  if (!confirm)
943
944
  {
944
945
  var p = $('<p/>').addClass('note confirm')
945
- .append("Are you sure you want to charge $" + parseFloat(t.amount).toFixed(2) + " to the customer?<br />")
946
+ .append("Are you sure you want to charge $" + parseFloat(amount).toFixed(2) + " to the customer?<br />")
946
947
  .append($('<input/>').attr('type','button').val('Yes').click(function() { that.capture_transaction(transaction_id, true); }))
947
948
  .append(' ')
948
949
  .append($('<input/>').attr('type','button').val('No').click(function() { $('#transactions_message').empty(); }));
@@ -952,10 +953,12 @@ InvoiceController.prototype = {
952
953
  $('#transactions_message').html("<p class='loading'>Capturing funds...</p>");
953
954
  $.ajax({
954
955
  url: '/admin/invoices/' + that.invoice.id + '/transactions/' + transaction_id + '/capture',
956
+ type: 'get',
957
+ data: { amount: amount },
955
958
  success: function(resp) {
956
- if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
957
- if (resp.success) { $('#message').empty(); that.refresh_transactions(); }
958
- if (resp.refresh) { $('#message').empty(); that.refresh_transactions(); }
959
+ if (resp.error) $('#transactions_message').html("<p class='note error'>" + resp.error + "</p>");
960
+ if (resp.success) { $('#transactions_message').empty(); that.refresh_transactions(); }
961
+ if (resp.refresh) { $('#transactions_message').empty(); that.refresh_transactions(); }
959
962
  }
960
963
  });
961
964
  },
@@ -1166,8 +1169,8 @@ InvoiceController.prototype = {
1166
1169
  {
1167
1170
  var that = this;
1168
1171
  var requires = false;
1169
- $.each(that.invoice.line_items, function(i, li) {
1170
- if (li.requires_shipping && !li.downloadable)
1172
+ $.each(that.invoice.line_items, function(i, li) {
1173
+ if (li.variant.requires_shipping && !li.variant.downloadable)
1171
1174
  requires = true;
1172
1175
  });
1173
1176
  return requires;
@@ -6,7 +6,7 @@ module Caboose
6
6
  return if !user_is_allowed('invoices', 'edit')
7
7
 
8
8
  it = InvoiceTransaction.find(params[:id])
9
- resp = it.capture
9
+ resp = params[:amount] ? it.capture(params[:amount]) : it.capture
10
10
 
11
11
  render :json => resp
12
12
  end
@@ -48,12 +48,16 @@ module Caboose
48
48
  end
49
49
 
50
50
  # Capture funds from a previously authorized transaction
51
- def capture
51
+ def capture(amount = nil)
52
52
 
53
53
  return { :error => "This invoice doesn't seem to be authorized." } if !self.success
54
54
 
55
55
  ct = InvoiceTransaction.where(:parent_id => self.id, :transaction_type => InvoiceTransaction::TYPE_CAPTURE, :success => true).first
56
56
  return { :error => "Funds for this invoice have already been captured." } if ct
57
+
58
+ # Make sure the amount given isn't greater than the invoice total
59
+ return { :error => "Amount given to capture is greater than the current invoice total." } if amount && amount.to_f > self.invoice.total.to_f
60
+ amount = self.invoice.total if amount.nil?
57
61
 
58
62
  resp = Caboose::StdClass.new
59
63
  sc = self.invoice.site.store_config
@@ -63,9 +67,10 @@ module Caboose
63
67
 
64
68
  Stripe.api_key = sc.stripe_secret_key.strip
65
69
  bt = nil
66
- begin
67
- c = Stripe::Charge.retrieve(self.transaction_id)
68
- c = c.capture
70
+ begin
71
+ c = Stripe::Charge.retrieve(self.transaction_id)
72
+ return { :error => "Amount given to capture is greater than the amount authorized." } if amount.to_f > (c.amount/100).to_f
73
+ c = c.capture({ :amount => (amount*100).to_i })
69
74
  bt = Stripe::BalanceTransaction.retrieve(c.balance_transaction)
70
75
  rescue Exception => ex
71
76
  resp.error = "Error during capture process\n#{ex.message}"
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.8.62'
2
+ VERSION = '0.8.63'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.62
4
+ version: 0.8.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg