1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Working on Bitcoin with Stripe

This commit is contained in:
Hillel Coren 2017-10-23 21:47:24 +03:00
parent 9a2581c610
commit 370be9e63c
8 changed files with 67 additions and 5 deletions

View File

@ -91,7 +91,7 @@ class StripePaymentDriver extends BasePaymentDriver
public function shouldUseSource() public function shouldUseSource()
{ {
return in_array($this->gatewayType, [GATEWAY_TYPE_ALIPAY, GATEWAY_TYPE_SOFORT]); return in_array($this->gatewayType, [GATEWAY_TYPE_ALIPAY, GATEWAY_TYPE_SOFORT, GATEWAY_TYPE_BITCOIN]);
} }
protected function checkCustomerExists($customer) protected function checkCustomerExists($customer)
@ -358,6 +358,7 @@ class StripePaymentDriver extends BasePaymentDriver
$amount = intval($this->invoice()->getRequestedAmount() * 100); $amount = intval($this->invoice()->getRequestedAmount() * 100);
$invoiceNumber = $this->invoice()->invoice_number; $invoiceNumber = $this->invoice()->invoice_number;
$currency = $this->client()->getCurrencyCode(); $currency = $this->client()->getCurrencyCode();
$email = $this->contact()->email;
$gatewayType = GatewayType::getAliasFromId($this->gatewayType); $gatewayType = GatewayType::getAliasFromId($this->gatewayType);
$redirect = url("/complete_source/{$this->invitation->invitation_key}/{$gatewayType}"); $redirect = url("/complete_source/{$this->invitation->invitation_key}/{$gatewayType}");
$country = $this->client()->country ? $this->client()->country->iso_3166_2 : ($this->account()->country ? $this->account()->country->iso_3166_2 : ''); $country = $this->client()->country ? $this->client()->country->iso_3166_2 : ($this->account()->country ? $this->account()->country->iso_3166_2 : '');
@ -368,6 +369,12 @@ class StripePaymentDriver extends BasePaymentDriver
throw new Exception('Alipay is not enabled'); throw new Exception('Alipay is not enabled');
} }
$type = 'alipay'; $type = 'alipay';
} elseif ($this->gatewayType == GATEWAY_TYPE_BITCOIN) {
if (! $this->accountGateway->getBitcoinEnabled()) {
throw new Exception('Bitcoin is not enabled');
}
$type = 'bitcoin';
$extra = "&owner[email]={$email}";
} else { } else {
if (! $this->accountGateway->getSofortEnabled()) { if (! $this->accountGateway->getSofortEnabled()) {
throw new Exception('Sofort is not enabled'); throw new Exception('Sofort is not enabled');
@ -383,7 +390,18 @@ class StripePaymentDriver extends BasePaymentDriver
$this->invitation->transaction_reference = $response['id']; $this->invitation->transaction_reference = $response['id'];
$this->invitation->save(); $this->invitation->save();
if ($this->gatewayType == GATEWAY_TYPE_BITCOIN) {
return view('payments/stripe/bitcoin', [
'client' => $this->client(),
'account' => $this->account(),
'invitation' => $this->invitation,
'invoiceNumber' => $invoiceNumber,
'amount' => $amount,
'source' => $response,
]);
} else {
return redirect($response['redirect']['url']); return redirect($response['redirect']['url']);
}
} else { } else {
throw new Exception($response); throw new Exception($response);
} }

View File

@ -38,7 +38,8 @@
"card": "^2.1.1", "card": "^2.1.1",
"fullcalendar": "^3.5.1", "fullcalendar": "^3.5.1",
"toastr": "^2.1.3", "toastr": "^2.1.3",
"jt.timepicker": "jquery-timepicker-jt#^1.11.12" "jt.timepicker": "jquery-timepicker-jt#^1.11.12",
"qrcode.js": "qrcode-js#*"
}, },
"resolutions": { "resolutions": {
"jquery": "~1.11" "jquery": "~1.11"

View File

@ -116,6 +116,10 @@ elixir(function(mix) {
bowerDir + '/card/dist/card.js', bowerDir + '/card/dist/card.js',
], 'public/js/card.min.js'); ], 'public/js/card.min.js');
mix.scripts([
bowerDir + '/qrcode.js/qrcode.js',
], 'public/js/qrcode.min.js');
mix.scripts([ mix.scripts([
bowerDir + '/tablesorter/dist/js/jquery.tablesorter.combined.js', bowerDir + '/tablesorter/dist/js/jquery.tablesorter.combined.js',
bowerDir + '/tablesorter/dist/js/widgets/widget-grouping.min.js', bowerDir + '/tablesorter/dist/js/widgets/widget-grouping.min.js',

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

2
public/js/qrcode.min.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -174,12 +174,12 @@
->label('SEPA') ->label('SEPA')
->text(trans('texts.enable_sepa')) ->text(trans('texts.enable_sepa'))
->value(1) !!} ->value(1) !!}
-->
{!! Former::checkbox('enable_bitcoin') {!! Former::checkbox('enable_bitcoin')
->label(trans('texts.bitcoin')) ->label(trans('texts.bitcoin'))
->text(trans('texts.enable_bitcoin')) ->text(trans('texts.enable_bitcoin'))
->value(1) !!} ->value(1) !!}
-->
{!! Former::checkbox('enable_alipay') {!! Former::checkbox('enable_alipay')
->label(trans('texts.alipay')) ->label(trans('texts.alipay'))
@ -312,6 +312,8 @@
$('#enable_ach').change(updateWebhookShown); $('#enable_ach').change(updateWebhookShown);
$('#enable_alipay').change(updateWebhookShown); $('#enable_alipay').change(updateWebhookShown);
$('#enable_sofort').change(updateWebhookShown); $('#enable_sofort').change(updateWebhookShown);
$('#enable_sepa').change(updateWebhookShown);
$('#enable_bitcoin').change(updateWebhookShown);
@if (!$accountGateway && count($secondaryGateways)) @if (!$accountGateway && count($secondaryGateways))
$('#primary_gateway_id').append($('<option>', { $('#primary_gateway_id').append($('<option>', {

View File

@ -0,0 +1,34 @@
@extends('payments.payment_method')
@section('head')
@parent
<script type="text/javascript" src="{{ asset('js/qrcode.min.js') }}"></script>
<script type="text/javascript">
$(function() {
var qrcode = new QRCode(document.getElementById("qrcode"), {
text: "{{ $source['bitcoin']['uri'] }}",
});
});
</script>
@stop
@section('payment_details')
<div class="row">
<div class="col-md-6">
<img src="{{ asset('/images/gateways/logo_Bitcoin.png') }}"/>
<p>&nbsp;</p>
<h2>{{ $source['bitcoin']['amount'] / 100000000 }} BTC</h2>
<h3>{{ $source['receiver']['address'] }}</h3>
<p>&nbsp;</p>
{!! Button::normal(strtoupper(trans('texts.cancel')))->large()->asLinkTo($invitation->getLink()) !!}
</div>
<div class="col-md-6">
<div id="qrcode"></div>
</div>
</div>
@stop