mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Added code for PHP-Payments to payment controller and to JSON for Composer.
This commit is contained in:
parent
11c6cff7ca
commit
b1a525a7f4
@ -129,8 +129,9 @@ class PaymentController extends \BaseController
|
|||||||
private function getPaymentDetails($invoice, $input = null)
|
private function getPaymentDetails($invoice, $input = null)
|
||||||
{
|
{
|
||||||
$key = $invoice->invoice_number . '_details';
|
$key = $invoice->invoice_number . '_details';
|
||||||
|
$paymentLibrary = $invoice->client->account->account_gateways[0]->gateway->paymentlibrary;
|
||||||
|
|
||||||
if ($input)
|
if ($input && $paymentLibrary->name == "Omnipay")
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'firstName' => $input['first_name'],
|
'firstName' => $input['first_name'],
|
||||||
@ -152,6 +153,33 @@ class PaymentController extends \BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
Session::put($key, $data);
|
Session::put($key, $data);
|
||||||
|
}
|
||||||
|
else if ($input && $paymentLibrary->name == "PHP-Payments")
|
||||||
|
{
|
||||||
|
$input = Input::all();
|
||||||
|
$data = [
|
||||||
|
'first_name' => $input['first_name'],
|
||||||
|
'last_name' => $input['last_name'],
|
||||||
|
'cc_number' => $input['card_number'],
|
||||||
|
'cc_exp' => $input['expiration_month'].$input['expiration_year'],
|
||||||
|
'cc_code' => $input['cvv'],
|
||||||
|
'street' => $input['address1'],
|
||||||
|
'street2' => $input['address2'],
|
||||||
|
'city' => $input['city'],
|
||||||
|
'state' => $input['state'],
|
||||||
|
'postal_code' => $input['postal_code'],
|
||||||
|
'amt' => $invoice->amount,
|
||||||
|
'ship_to_street' => $input['address1'],
|
||||||
|
'ship_to_city' => $input['city'],
|
||||||
|
'ship_to_state' => $input['state'],
|
||||||
|
'ship_to_postal_code' => $input['postal_code'],
|
||||||
|
'currency_code' => $invoice->client->currency->code,
|
||||||
|
'returnUrl' => URL::to('complete'),
|
||||||
|
'cancelUrl' => URL::to('/')
|
||||||
|
];
|
||||||
|
|
||||||
|
Session::put($key, $data);
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
else if (Session::get($key))
|
else if (Session::get($key))
|
||||||
{
|
{
|
||||||
@ -235,7 +263,7 @@ class PaymentController extends \BaseController
|
|||||||
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
|
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
|
||||||
$invoice = $invitation->invoice;
|
$invoice = $invitation->invoice;
|
||||||
$accountGateway = $invoice->client->account->account_gateways[0];
|
$accountGateway = $invoice->client->account->account_gateways[0];
|
||||||
$gateway = self::createGateway($accountGateway);
|
$paymentLibrary = $accountGateway->gateway->paymentlibrary;
|
||||||
|
|
||||||
if ($onSite)
|
if ($onSite)
|
||||||
{
|
{
|
||||||
@ -247,44 +275,85 @@ class PaymentController extends \BaseController
|
|||||||
$client->postal_code = trim(Input::get('postal_code'));
|
$client->postal_code = trim(Input::get('postal_code'));
|
||||||
$client->save();
|
$client->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$details = self::getPaymentDetails($invoice, Input::all());
|
if($paymentLibrary->name == "Omnipay")
|
||||||
$response = $gateway->purchase($details)->send();
|
{
|
||||||
$ref = $response->getTransactionReference();
|
$gateway = self::createGateway($accountGateway);
|
||||||
|
$details = self::getPaymentDetails($invoice, Input::all());
|
||||||
if (!$ref)
|
$response = $gateway->purchase($details)->send();
|
||||||
{
|
$ref = $response->getTransactionReference();
|
||||||
Session::flash('error', $response->getMessage());
|
|
||||||
return Redirect::to('payment/' . $invitationKey)
|
if (!$ref)
|
||||||
->withInput();
|
{
|
||||||
|
Session::flash('error', $response->getMessage());
|
||||||
|
return Redirect::to('payment/' . $invitationKey)
|
||||||
|
->withInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($response->isSuccessful())
|
||||||
|
{
|
||||||
|
$payment = self::createPayment($invitation, $ref);
|
||||||
|
|
||||||
|
$invoice->invoice_status_id = INVOICE_STATUS_PAID;
|
||||||
|
$invoice->save();
|
||||||
|
|
||||||
|
Event::fire('invoice.paid', $payment);
|
||||||
|
|
||||||
|
Session::flash('message', 'Successfully applied payment');
|
||||||
|
return Redirect::to('view/' . $payment->invitation->invitation_key);
|
||||||
|
}
|
||||||
|
else if ($response->isRedirect())
|
||||||
|
{
|
||||||
|
$invitation->transaction_reference = $ref;
|
||||||
|
$invitation->save();
|
||||||
|
|
||||||
|
$response->redirect();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Session::flash('error', $response->getMessage());
|
||||||
|
return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if ($input && $paymentLibrary->name == "PHP-Payments")
|
||||||
|
{
|
||||||
|
$p = new PHP_Payments;
|
||||||
|
|
||||||
|
$config = Payment_Utility::load('config', '/path/to/your/gateway/config');
|
||||||
|
$details = self::getPaymentDetails($invoice, Input::all());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$response = $p->oneoff_payment('name_of_payment_driver', $details, $config);
|
||||||
|
|
||||||
if ($response->isSuccessful())
|
if ($response->status == 'Success')
|
||||||
{
|
{
|
||||||
$payment = self::createPayment($invitation, $ref);
|
$payment = self::createPayment($invitation, $ref);
|
||||||
|
|
||||||
$invoice->invoice_status_id = INVOICE_STATUS_PAID;
|
$invoice->invoice_status_id = INVOICE_STATUS_PAID;
|
||||||
$invoice->save();
|
$invoice->save();
|
||||||
|
|
||||||
Event::fire('invoice.paid', $payment);
|
Event::fire('invoice.paid', $payment);
|
||||||
|
|
||||||
Session::flash('message', 'Successfully applied payment');
|
Session::flash('message', 'Successfully applied payment');
|
||||||
return Redirect::to('view/' . $payment->invitation->invitation_key);
|
return Redirect::to('view/' . $payment->invitation->invitation_key);
|
||||||
}
|
}
|
||||||
else if ($response->isRedirect())
|
else if ($response->isRedirect())
|
||||||
{
|
{
|
||||||
$invitation->transaction_reference = $ref;
|
$invitation->transaction_reference = $ref;
|
||||||
$invitation->save();
|
$invitation->save();
|
||||||
|
|
||||||
$response->redirect();
|
$response->redirect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Session::flash('error', $response->getMessage());
|
Session::flash('error', $response->getMessage());
|
||||||
return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->getMessage());
|
return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->getMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
"app/database/migrations",
|
"app/database/migrations",
|
||||||
"app/database/seeds",
|
"app/database/seeds",
|
||||||
"app/tests/TestCase.php",
|
"app/tests/TestCase.php",
|
||||||
"app/libraries"
|
"app/libraries",
|
||||||
|
"vendor/php-payments/lib"
|
||||||
],
|
],
|
||||||
"psr-0" : {
|
"psr-0" : {
|
||||||
"ninja" : "app/"
|
"ninja" : "app/"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user