Skip to content

Commit

Permalink
Added Paymill
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Mar 7, 2018
1 parent 395ce63 commit 5c5dd7a
Show file tree
Hide file tree
Showing 18 changed files with 324 additions and 146 deletions.
1 change: 1 addition & 0 deletions app/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
define('GATEWAY_BRAINTREE', 61);
define('GATEWAY_CUSTOM', 62);
define('GATEWAY_GOCARDLESS', 64);
define('GATEWAY_PAYMILL', 66);

// The customer exists, but only as a local concept
// The remote gateway doesn't understand the concept of customers
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private function showOnlinePayments()
$trashedCount = AccountGateway::scope()->withTrashed()->count();

if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) {
if (! $accountGateway->getPublishableStripeKey()) {
if (! $accountGateway->getPublishableKey()) {
Session::now('warning', trans('texts.missing_publishable_key'));
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/AccountGatewayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public function save($accountGatewayPublicId = false)

if ($gatewayId == GATEWAY_DWOLLA) {
$optional = array_merge($optional, ['key', 'secret']);
} elseif ($gatewayId == GATEWAY_PAYMILL) {
$rules['publishable_key'] = 'required';
} elseif ($gatewayId == GATEWAY_STRIPE) {
if (Utils::isNinjaDev()) {
// do nothing - we're unable to acceptance test with StripeJS
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/HandleUserLoggedIn.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function handle(UserLoggedIn $event)

// if they're using Stripe make sure they're using Stripe.js
$accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE);
if ($accountGateway && ! $accountGateway->getPublishableStripeKey()) {
if ($accountGateway && ! $accountGateway->getPublishableKey()) {
Session::flash('warning', trans('texts.missing_publishable_key'));
} elseif ($account->isLogoTooLarge()) {
Session::flash('warning', trans('texts.logo_too_large', ['size' => $account->getLogoSize() . 'KB']));
Expand Down
19 changes: 14 additions & 5 deletions app/Models/AccountGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ public function paymentDriver($invitation = false, $gatewayTypeId = false)
*/
public function isGateway($gatewayId)
{
return $this->gateway_id == $gatewayId;
if (is_array($gatewayId)) {
foreach ($gatewayId as $id) {
if ($this->gateway_id == $id) {
return true;
}
}
return false;
} else {
return $this->gateway_id == $gatewayId;
}
}

/**
Expand Down Expand Up @@ -127,9 +136,9 @@ public function getConfigField($field)
/**
* @return bool|mixed
*/
public function getPublishableStripeKey()
public function getPublishableKey()
{
if (! $this->isGateway(GATEWAY_STRIPE)) {
if (! $this->isGateway([GATEWAY_STRIPE, GATEWAY_PAYMILL])) {
return false;
}

Expand Down Expand Up @@ -254,7 +263,7 @@ public function getPlaidEnvironment()
return null;
}

$stripe_key = $this->getPublishableStripeKey();
$stripe_key = $this->getPublishableKey();

return substr(trim($stripe_key), 0, 8) == 'pk_test_' ? 'tartan' : 'production';
}
Expand All @@ -272,7 +281,7 @@ public function getWebhookUrl()
public function isTestMode()
{
if ($this->isGateway(GATEWAY_STRIPE)) {
return strpos($this->getPublishableStripeKey(), 'test') !== false;
return strpos($this->getPublishableKey(), 'test') !== false;
} else {
return $this->getConfigField('testMode');
}
Expand Down
27 changes: 27 additions & 0 deletions app/Ninja/PaymentDrivers/PaymillPaymentDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Ninja\PaymentDrivers;

class PaymillPaymentDriver extends BasePaymentDriver
{
public function tokenize()
{
return true;
}

protected function paymentDetails($paymentMethod = false)
{
$data = parent::paymentDetails($paymentMethod);

if ($paymentMethod) {
return $data;
}

if (! empty($this->input['sourceToken'])) {
$data['token'] = $this->input['sourceToken'];
unset($data['card']);
}

return $data;
}
}
2 changes: 1 addition & 1 deletion app/Ninja/PaymentDrivers/StripePaymentDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function gatewayTypes()

public function tokenize()
{
return $this->accountGateway->getPublishableStripeKey();
return $this->accountGateway->getPublishableKey();
}

public function rules()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"google/apiclient": "^2.0",
"guzzlehttp/guzzle": "~6.0",
"intervention/image": "dev-master",
"invoiceninja/omnipay-collection": "0.6@dev",
"invoiceninja/omnipay-collection": "0.7@dev",
"jaybizzle/laravel-crawler-detect": "1.*",
"jlapp/swaggervel": "master-dev",
"jonnyw/php-phantomjs": "dev-fixes",
Expand Down
63 changes: 54 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions database/seeds/PaymentLibrariesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function run()
['name' => 'FirstData Payeezy', 'provider' => 'FirstData_Payeezy'],
['name' => 'GoCardless', 'provider' => 'GoCardlessV2\Redirect', 'sort_order' => 9, 'is_offsite' => true],
['name' => 'PagSeguro', 'provider' => 'PagSeguro'],
['name' => 'PAYMILL', 'provider' => 'Paymill'],
];

foreach ($gateways as $gateway) {
Expand Down
13 changes: 7 additions & 6 deletions resources/views/accounts/account_gateway.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{!! Former::populateField('show_address', intval($accountGateway->show_address)) !!}
{!! Former::populateField('show_shipping_address', intval($accountGateway->show_shipping_address)) !!}
{!! Former::populateField('update_address', intval($accountGateway->update_address)) !!}
{!! Former::populateField('publishable_key', $accountGateway->getPublishableStripeKey() ? str_repeat('*', strlen($accountGateway->getPublishableStripeKey())) : '') !!}
{!! Former::populateField('publishable_key', $accountGateway->getPublishableKey() ? str_repeat('*', strlen($accountGateway->getPublishableKey())) : '') !!}
{!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? 1 : 0) !!}
{!! Former::populateField('enable_apple_pay', $accountGateway->getApplePayEnabled() ? 1 : 0) !!}
{!! Former::populateField('enable_sofort', $accountGateway->getSofortEnabled() ? 1 : 0) !!}
Expand Down Expand Up @@ -84,13 +84,12 @@
@endif
@endif

@foreach ($gateways as $gateway)
<span id="publishableKey" style="display: none">
{!! Former::text('publishable_key') !!}
</span>

@foreach ($gateways as $gateway)
<div id="gateway_{{ $gateway->id }}_div" class='gateway-fields' style="display: none">
@if ($gateway->id == GATEWAY_STRIPE)
{!! Former::text('publishable_key') !!}
@endif

@foreach ($gateway->fields as $field => $details)

@if ($details && (!$accountGateway || !$accountGateway->getConfigField($field)) && !is_array($details) && !is_bool($details))
Expand Down Expand Up @@ -321,6 +320,8 @@ function setFieldsShown() {
} else {
$('.stripe-ach').hide();
}
$('#publishableKey').toggle([{{ GATEWAY_STRIPE }}, {{ GATEWAY_PAYMILL }}].indexOf(gateway.id) >= 0);
}
function gatewayLink(url) {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/invoices/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function payWithWepay() {
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
<script type="text/javascript">
// https://stripe.com/docs/stripe-js/elements/payment-request-button
var stripe = Stripe('{{ $accountGateway->getPublishableStripeKey() }}');
var stripe = Stripe('{{ $accountGateway->getPublishableKey() }}');
var paymentRequest = stripe.paymentRequest({
country: '{{ $invoice->client->getCountryCode() }}',
currency: '{{ strtolower($invoice->client->getCurrencyCode()) }}',
Expand Down
2 changes: 1 addition & 1 deletion resources/views/payments/apple_pay.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
<script type="text/javascript">
// https://stripe.com/docs/stripe-js/elements/payment-request-button
var stripe = Stripe('{{ $accountGateway->getPublishableStripeKey() }}');
var stripe = Stripe('{{ $accountGateway->getPublishableKey() }}');
var paymentRequest = stripe.paymentRequest({
country: '{{ $client->getCountryCode() }}',
currency: '{{ strtolower($client->getCurrencyCode()) }}',
Expand Down
Loading

0 comments on commit 5c5dd7a

Please sign in to comment.