Created
October 22, 2014 05:06
-
-
Save derwiki/551c5c82d2220aced013 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pay_lender!(token = nil) | |
fail unless lender.stripe_recipient_id || token | |
recipient = lender.stripe_recipient_id || | |
create_recipient!(token, lender.name).id | |
Stripe::Transfer.create( | |
amount: (lender_profit * 100).round, | |
currency: "usd", | |
recipient: lender.stripe_recipient_id, | |
statement_description: "CameraLends Lending" | |
) | |
end | |
def create_recipient!(token, name) | |
Stripe::Recipient.create( | |
name: name, | |
type: "individual", | |
email: item.owner.email, | |
bank_account: token | |
).tap do |recipient| | |
lender.update_attributes stripe_recipient_id: recipient.id | |
end | |
end | |
var $bankForm = $('#bank-form'); | |
$bankForm.submit(function(event) { | |
event.preventDefault(); | |
// Disable the submit button to prevent repeated clicks | |
$('.submit-button').prop('disabled', true); | |
Stripe.setPublishableKey($bankForm.data('stripe-publishable-key')); | |
Stripe.bankAccount.createToken({ | |
country: 'US', | |
routingNumber: $bankForm.find('.routing-number input').val(), | |
accountNumber: $bankForm.find('.account-number input').val(), | |
}, stripeBankResponseHandler); | |
}); | |
function stripeBankResponseHandler(status, response) { | |
if (response.error) { | |
// Show the errors on the form | |
$('.bank-errors').text(response.error.message); | |
$('.submit-button').prop('disabled', false); | |
return false; | |
} else { | |
// token contains id, last4, and card type | |
var token = response.id; | |
// Insert the token into the form so it gets submitted to the server | |
$bankForm.append($('<input type="hidden" name="bank[stripe_token]" />').val(token)); | |
// and submit | |
$bankForm.get(0).submit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment