1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Manually merging PR #630

This commit is contained in:
Hillel Coren 2016-01-18 11:13:39 +02:00
parent cbe2b2905e
commit 89ff1be14f
8 changed files with 76 additions and 50 deletions

View File

@ -84,6 +84,7 @@ class AccountGatewayController extends BaseController
$data['selectGateways'] = Gateway::where('payment_library_id', '=', 1)
->where('id', '!=', GATEWAY_PAYPAL_EXPRESS)
->where('id', '!=', GATEWAY_BITPAY)
->where('id', '!=', GATEWAY_GOCARDLESS)
->where('id', '!=', GATEWAY_DWOLLA)
->orderBy('name')->get();
$data['hiddenFields'] = Gateway::$hiddenFields;
@ -104,6 +105,9 @@ class AccountGatewayController extends BaseController
if ($type == PAYMENT_TYPE_BITCOIN) {
$paymentTypes[$type] .= ' - BitPay';
}
if ($type == PAYMENT_TYPE_DIRECT_DEBIT) {
$paymentTypes[$type] .= ' - GoCardless';
}
}
}
@ -173,6 +177,8 @@ class AccountGatewayController extends BaseController
$gatewayId = GATEWAY_PAYPAL_EXPRESS;
} elseif ($paymentType == PAYMENT_TYPE_BITCOIN) {
$gatewayId = GATEWAY_BITPAY;
} elseif ($paymentType == PAYMENT_TYPE_DIRECT_DEBIT) {
$gatewayId = GATEWAY_GOCARDLESS;
} elseif ($paymentType == PAYMENT_TYPE_DWOLLA) {
$gatewayId = GATEWAY_DWOLLA;
}

View File

@ -125,6 +125,7 @@ class PaymentController extends BaseController
public function show_payment($invitationKey, $paymentType = false)
{
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$invoice = $invitation->invoice;
$client = $invoice->client;
@ -137,6 +138,7 @@ class PaymentController extends BaseController
$paymentType = Session::get($invitation->id . 'payment_type') ?:
$account->account_gateways[0]->getPaymentType();
}
if ($paymentType == PAYMENT_TYPE_TOKEN) {
$useToken = true;
$paymentType = PAYMENT_TYPE_CREDIT_CARD;
@ -145,8 +147,10 @@ class PaymentController extends BaseController
$accountGateway = $invoice->client->account->getGatewayByType($paymentType);
$gateway = $accountGateway->gateway;
$acceptedCreditCardTypes = $accountGateway->getCreditcardTypes();
// Handle offsite payments
if ($useToken || $paymentType != PAYMENT_TYPE_CREDIT_CARD
|| $gateway->id == GATEWAY_EWAY
@ -353,6 +357,7 @@ class PaymentController extends BaseController
$account = $client->account;
$accountGateway = $account->getGatewayByType(Session::get($invitation->id . 'payment_type'));
$rules = [
'first_name' => 'required',
'last_name' => 'required',
@ -434,12 +439,15 @@ class PaymentController extends BaseController
$response = $gateway->purchase($details)->send();
if ($accountGateway->gateway_id == GATEWAY_EWAY) {
$ref = $response->getData()['AccessCode'];
} elseif ($accountGateway->gateway_id == GATEWAY_TWO_CHECKOUT) {
$ref = $response->getData()['cart_order_id'];
} elseif ($accountGateway->gateway_id == GATEWAY_PAYFAST) {
$ref = $response->getData()['m_payment_id'];
} elseif ($accountGateway->gateway_id == GATEWAY_GOCARDLESS) {
$ref = $response->getData()['signature'];
} else {
$ref = $response->getTransactionReference();
}
@ -466,6 +474,7 @@ class PaymentController extends BaseController
return Redirect::to('view/'.$payment->invitation->invitation_key);
} elseif ($response->isRedirect()) {
$invitation->transaction_reference = $ref;
$invitation->save();
Session::put('transaction_reference', $ref);
@ -515,7 +524,6 @@ class PaymentController extends BaseController
$this->error('No-Payment-Type', false, false);
return Redirect::to($invitation->getLink());
}
$accountGateway = $account->getGatewayByType($paymentType);
$gateway = $this->paymentService->createGateway($accountGateway);
@ -535,7 +543,9 @@ class PaymentController extends BaseController
&& !$accountGateway->isGateway(GATEWAY_TWO_CHECKOUT)
&& !$accountGateway->isGateway(GATEWAY_CHECKOUT_COM)) {
$details = $this->paymentService->getPaymentDetails($invitation, $accountGateway);
$response = $this->paymentService->completePurchase($gateway, $accountGateway, $details, $token);
$ref = $response->getTransactionReference() ?: $token;
if ($response->isCancelled()) {
@ -554,6 +564,7 @@ class PaymentController extends BaseController
return Redirect::to($invitation->getLink());
}
} catch (\Exception $e) {
$this->error('Offsite-uncaught', false, $accountGateway, $e);
return Redirect::to($invitation->getLink());
}

View File

@ -417,6 +417,7 @@ if (!defined('CONTACT_EMAIL')) {
define('GATEWAY_PAYPAL_EXPRESS', 17);
define('GATEWAY_PAYPAL_PRO', 18);
define('GATEWAY_STRIPE', 23);
define('GATEWAY_GOCARDLESS', 6);
define('GATEWAY_TWO_CHECKOUT', 27);
define('GATEWAY_BEANSTREAM', 29);
define('GATEWAY_PSIGATE', 30);
@ -484,6 +485,7 @@ if (!defined('CONTACT_EMAIL')) {
define('PAYMENT_TYPE_PAYPAL', 'PAYMENT_TYPE_PAYPAL');
define('PAYMENT_TYPE_CREDIT_CARD', 'PAYMENT_TYPE_CREDIT_CARD');
define('PAYMENT_TYPE_DIRECT_DEBIT', 'PAYMENT_TYPE_DIRECT_DEBIT');
define('PAYMENT_TYPE_BITCOIN', 'PAYMENT_TYPE_BITCOIN');
define('PAYMENT_TYPE_DWOLLA', 'PAYMENT_TYPE_DWOLLA');
define('PAYMENT_TYPE_TOKEN', 'PAYMENT_TYPE_TOKEN');

View File

@ -12,7 +12,8 @@ class Gateway extends Eloquent
PAYMENT_TYPE_CREDIT_CARD,
PAYMENT_TYPE_PAYPAL,
PAYMENT_TYPE_BITCOIN,
PAYMENT_TYPE_DWOLLA
PAYMENT_TYPE_DIRECT_DEBIT,
PAYMENT_TYPE_DWOLLA,
];
public static $hiddenFields = [
@ -94,6 +95,8 @@ class Gateway extends Eloquent
return PAYMENT_TYPE_BITCOIN;
} else if ($gatewayId == GATEWAY_DWOLLA) {
return PAYMENT_TYPE_DWOLLA;
}else if ($gatewayId == GATEWAY_GOCARDLESS) {
return PAYMENT_TYPE_DIRECT_DEBIT;
} else {
return PAYMENT_TYPE_CREDIT_CARD;
}

View File

@ -254,6 +254,7 @@ class PaymentService extends BaseService
$response = $gateway->fetchTransaction($details)->send();
return $gateway->fetchTransaction($details)->send();
} else {
return $gateway->completePurchase($details)->send();
}
}

View File

@ -593,6 +593,7 @@ return array(
'payment_type_credit_card' => 'Credit Card',
'payment_type_paypal' => 'PayPal',
'payment_type_bitcoin' => 'Bitcoin',
'payment_type_direct_debit' => 'Direct Debit',
'knowledge_base' => 'Knowledge Base',
'partial' => 'Partial',
'partial_remaining' => ':partial of :balance',

View File

@ -134,6 +134,8 @@
setFieldsShown({{ GATEWAY_PAYPAL_EXPRESS }});
} else if (val == 'PAYMENT_TYPE_DWOLLA') {
setFieldsShown({{ GATEWAY_DWOLLA }});
} else if (val == 'PAYMENT_TYPE_DIRECT_DEBIT') {
setFieldsShown({{ GATEWAY_GOCARDLESS }});
} else {
setFieldsShown({{ GATEWAY_BITPAY }});
}