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

Updated code to fix issues with BeanStream payments.

This commit is contained in:
blkmutt 2014-04-05 21:49:21 -04:00
parent 227282a8cf
commit 638d26adb8
3 changed files with 55 additions and 16 deletions

View File

@ -472,7 +472,17 @@ class AccountController extends \BaseController {
{
if (!in_array($field, ['testMode', 'developerMode', 'headerImageUrl', 'solutionType', 'landingPage', 'brandName']))
{
$rules[$gateway->id.'_'.$field] = 'required';
if(strtolower($gateway->name) == 'beanstream')
{
if(in_array($field, ['merchant_id', 'passCode']))
{
$rules[$gateway->id.'_'.$field] = 'required';
}
}
else
{
$rules[$gateway->id.'_'.$field] = 'required';
}
}
}
}

View File

@ -129,7 +129,8 @@ class PaymentController extends \BaseController
private function getPaymentDetails($invoice, $input = null)
{
$key = $invoice->invoice_number . '_details';
$paymentLibrary = $invoice->client->account->account_gateways[0]->gateway->paymentlibrary;
$gateway = $invoice->client->account->account_gateways[0]->gateway;
$paymentLibrary = $gateway->paymentlibrary;
if ($input && $paymentLibrary->name == "Omnipay")
{
@ -174,10 +175,21 @@ class PaymentController extends \BaseController
'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('/')
];
if(strtolower($gateway->name) == 'beanstream')
{
$data['phone'] = $input['phone'];
$data['email'] = $input['email'];
$data['country'] = $input['country'];
$data['ship_to_country'] = $input['country'];
}
if(strlen($data['cc_exp']) == 5)
{
$data['cc_exp'] = '0'.$data['cc_exp'];
}
Session::put($key, $data);
return $data;
}
@ -211,8 +223,9 @@ class PaymentController extends \BaseController
public function show_payment($invitationKey)
{
// For PayPal Express we redirect straight to their site
$invitation = Invitation::with('invoice.client.account')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$invitation = Invitation::with('invoice.client.account', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$account = $invitation->invoice->client->account;
if ($account->isGatewayConfigured(GATEWAY_PAYPAL_EXPRESS))
{
if (Session::has('error'))
@ -226,16 +239,21 @@ class PaymentController extends \BaseController
}
}
$invitation = Invitation::with('contact', 'invoice.client')->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;
$client = $invoice->client;
$gateway = $invoice->client->account->account_gateways[0]->gateway;
$paymentLibrary = $gateway->paymentlibrary;
$data = [
'showBreadcrumbs' => false,
'invitationKey' => $invitationKey,
'invoice' => $invoice,
'client' => $client,
'contact' => $invitation->contact
'contact' => $invitation->contact,
'paymentLibrary' => $paymentLibrary ,
'gateway' => $gateway,
'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(),
];
return View::make('payments.payment', $data);
@ -325,7 +343,7 @@ class PaymentController extends \BaseController
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")
else if ($paymentLibrary->name == "PHP-Payments")
{
$provider = $accountGateway->gateway->provider;
$p = new PHP_Payments;
@ -335,9 +353,9 @@ class PaymentController extends \BaseController
$response = $p->oneoff_payment($provider, $details, $config);
if ($response->status == 'Success')
if (strtolower($response->status) == 'success')
{
$payment = self::createPayment($invitation, $ref);
$payment = self::createPayment($invitation, $response->response_message);
$invoice->invoice_status_id = INVOICE_STATUS_PAID;
$invoice->save();
@ -349,8 +367,8 @@ class PaymentController extends \BaseController
}
else
{
Session::flash('error', $response->details);
return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->reason);
Session::flash('error', $response->response_message);
return Utils::fatalError('Sorry, there was an error processing your payment. Please try again later.<p>', $response->response_message);
}
}
}

View File

@ -19,7 +19,10 @@
'address1' => 'required',
'city' => 'required',
'state' => 'required',
'postal_code' => 'required'
'postal_code' => 'required',
'country' => 'required',
'phone' => 'required',
'email' => 'required'
)) }}
{{ Former::populate($client) }}
{{ Former::populateField('first_name', $contact->first_name) }}
@ -66,6 +69,14 @@
{{ Former::text('state')->label('State/Province') }}
{{ Former::text('postal_code') }}
<?php if(strtolower($gateway->name) == 'beanstream') { ?>
{{ Former::select('country')->addOption('','')->label('Country')
->fromQuery($countries, 'name', 'iso_3166_2') }}
{{ Former::text('phone') }}
{{ Former::text('email') }}
<?php } ?>
<?php echo($gateway->name); ?>
{{ Former::actions( Button::primary_submit_lg('Pay Now - ' . Utils::formatMoney($invoice->amount, $client->currency_id) )) }}
</div>