1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-19 16:01:34 +02:00

Added support for partial payments

This commit is contained in:
Hillel Coren 2015-04-17 14:57:17 +03:00
parent 96a71864ed
commit 168bb7cfb0
17 changed files with 44 additions and 28 deletions

View File

@ -246,8 +246,7 @@ class PaymentController extends BaseController
private function getPaymentDetails($invitation, $input = null)
{
$invoice = $invitation->invoice;
$key = $invoice->invoice_number.'_details';
$gateway = $invoice->client->account->getGatewayByType(Session::get('payment_type'))->gateway;
$key = $invoice->account_id.'-'.$invoice->invoice_number;
$currencyCode = $invoice->client->currency ? $invoice->client->currency->code : ($invoice->account->currency ? $invoice->account->currency->code : 'USD');
if ($input) {
@ -568,6 +567,7 @@ class PaymentController extends BaseController
$invitation->transaction_reference = $ref;
$invitation->save();
Session::put('transaction_reference', $ref);
Session::save();
$response->redirect();
} else {
@ -630,6 +630,14 @@ class PaymentController extends BaseController
$payerId = Request::query('PayerID');
$token = Request::query('token');
if (!$token) {
$token = Session::pull('transaction_reference');
}
if (!$token) {
return redirect(NINJA_WEB_URL);
}
$invitation = Invitation::with('invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('transaction_reference', '=', $token)->firstOrFail();
$invoice = $invitation->invoice;
@ -637,20 +645,26 @@ class PaymentController extends BaseController
$gateway = self::createGateway($accountGateway);
try {
$details = self::getPaymentDetails($invitation);
$response = $gateway->completePurchase($details)->send();
$ref = $response->getTransactionReference();
if (method_exists($gateway, 'completePurchase')) {
$details = self::getPaymentDetails($invitation);
$response = $gateway->completePurchase($details)->send();
$ref = $response->getTransactionReference();
if ($response->isSuccessful()) {
$payment = self::createPayment($invitation, $ref, $payerId);
if ($response->isSuccessful()) {
$payment = self::createPayment($invitation, $ref, $payerId);
Session::flash('message', trans('texts.applied_payment'));
Session::flash('message', trans('texts.applied_payment'));
return Redirect::to('view/'.$invitation->invitation_key);
} else {
$errorMessage = trans('texts.payment_error')."\n\n".$response->getMessage();
Session::flash('error', $errorMessage);
Utils::logError($errorMessage);
return Redirect::to('view/'.$invitation->invitation_key);
return Redirect::to('view/'.$invitation->invitation_key);
}
} else {
$errorMessage = trans('texts.payment_error')."\n\n".$response->getMessage();
Session::flash('error', $errorMessage);
Utils::logError($errorMessage);
$payment = self::createPayment($invitation, $token, $payerId);
Session::flash('message', trans('texts.applied_payment'));
return Redirect::to('view/'.$invitation->invitation_key);
}

View File

@ -22,6 +22,8 @@ class Gateway extends Eloquent
$link = 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run';
} elseif ($this->id == GATEWAY_TWO_CHECKOUT) {
$link = 'https://www.2checkout.com/referral?r=2c37ac2298';
} elseif ($this->id == GATEWAY_BITPAY) {
$link = 'https://bitpay.com/dashboard/signup';
}
$key = 'texts.gateway_help_'.$this->id;

View File

@ -46,8 +46,8 @@ Developed by [@hillelcoren](https://twitter.com/hillelcoren) | Designed by [kant
### Steps to setup from GitHub
If you plan on submitting changes it's best to [fork the repo](https://help.github.com/articles/fork-a-repo), otherwise you can just checkout the code.
git clone https://github.com/hillelcoren/invoice-ninja.git ninja
git clone git@github.com:hillelcoren/invoice-ninja.git ninja
cd ninja
Install Laravel packages using Composer

View File

@ -587,7 +587,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -578,7 +578,7 @@ return array(
'resend_confirmation' => 'Bestätigungsmail erneut senden',
'confirmation_resent' => 'Bestätigungsemail wurde erneut gesendet',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -585,7 +585,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -557,7 +557,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -586,7 +586,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -578,7 +578,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -580,7 +580,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -588,7 +588,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -586,7 +586,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -581,7 +581,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -581,7 +581,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -584,7 +584,7 @@ return array(
'resend_confirmation' => 'Resend confirmation email',
'confirmation_resent' => 'The confirmation email was resent',
'gateway_help_42' => 'Note: use a BitPay Legacy API Key, not an API token.',
'gateway_help_42' => ':link to sign up for BitPay.<br/>Note: use a Legacy API Key, not an API token.',
'payment_type_credit_card' => 'Credit card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',

View File

@ -22,7 +22,7 @@
@endforeach
@endif
@else
{!! Former::populateField('gateway_id', GATEWAY_AUTHORIZE_NET) !!}
{!! Former::populateField('gateway_id', GATEWAY_STRIPE) !!}
@endif
{!! Former::select('payment_type_id')

View File

@ -1655,7 +1655,7 @@
}
@if ($data)
window.model = new ViewModel({{ $data }});
window.model = new ViewModel({!! $data !!});
@else
window.model = new ViewModel();
model.addTaxRate();