From ce04c994dda4cca616f5dd729236774ed2fbc508 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Fri, 13 May 2016 09:30:22 -0400 Subject: [PATCH] Support payments and storing cards via WePay. --- .../Controllers/AccountGatewayController.php | 2 +- app/Http/Controllers/PaymentController.php | 73 +++--- .../Controllers/PublicClientController.php | 7 +- app/Http/routes.php | 6 +- app/Libraries/Utils.php | 2 +- app/Models/Account.php | 2 + app/Services/AccountGatewayService.php | 4 +- app/Services/PaymentService.php | 210 +++++++++++----- .../payments/add_paymentmethod.blade.php | 234 +----------------- .../payments/paymentmethods_list.blade.php | 1 + .../payments/tokenization_braintree.blade.php | 61 +++++ .../payments/tokenization_stripe.blade.php | 154 ++++++++++++ .../payments/tokenization_wepay.blade.php | 52 ++++ 13 files changed, 480 insertions(+), 328 deletions(-) create mode 100644 resources/views/payments/tokenization_braintree.blade.php create mode 100644 resources/views/payments/tokenization_stripe.blade.php create mode 100644 resources/views/payments/tokenization_wepay.blade.php diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index a192538480e9..27d3d54464d2 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -449,7 +449,7 @@ class AccountGatewayController extends BaseController 'tokenType' => $wepayUser->token_type, 'tokenExpires' => $accessTokenExpires, 'accountId' => $wepayAccount->account_id, - 'testMode' => WEPAY_ENVIRONMENT == WEPAY_STAGING, + 'testMode' => WEPAY_ENVIRONMENT == WEPAY_STAGE, )); $account->account_gateways()->save($accountGateway); diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 8f09c2980a59..e14a9cb9cd69 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -152,6 +152,8 @@ class PaymentController extends BaseController $data = array(); + Session::put($invitation->id.'payment_ref', $invoice->id.'_'.uniqid()); + if ($paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) { if ($paymentType == PAYMENT_TYPE_TOKEN) { $useToken = true; @@ -198,6 +200,10 @@ class PaymentController extends BaseController $data['braintreeClientToken'] = $this->paymentService->getBraintreeClientToken($account); } + if(!empty($data['braintreeClientToken']) || $accountGateway->getPublishableStripeKey()|| $accountGateway->gateway_id == GATEWAY_WEPAY) { + $data['tokenize'] = true; + } + } else { if ($deviceData = Input::get('details')) { Session::put($invitation->id . 'device_data', $deviceData); @@ -405,7 +411,7 @@ class PaymentController extends BaseController 'last_name' => 'required', ]; - if ( ! Input::get('stripeToken') && ! Input::get('payment_method_nonce') && !(Input::get('plaidPublicToken') && Input::get('plaidAccountId'))) { + if ( ! Input::get('sourceToken') && !(Input::get('plaidPublicToken') && Input::get('plaidAccountId'))) { $rules = array_merge( $rules, [ @@ -459,8 +465,6 @@ class PaymentController extends BaseController $paymentType = Session::get($invitation->id . 'payment_type'); $accountGateway = $account->getGatewayByType($paymentType); $paymentMethod = null; - - if ($useToken) { if(!$sourceId) { @@ -492,21 +496,46 @@ class PaymentController extends BaseController $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway, $data); // check if we're creating/using a billing token + $tokenBillingSupported = false; if ($accountGateway->gateway_id == GATEWAY_STRIPE) { + $tokenBillingSupported = true; + $customerReferenceParam = 'cardReference'; + if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && !Input::get('authorize_ach')) { Session::flash('error', trans('texts.ach_authorization_required')); return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); } + } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { + $tokenBillingSupported = true; + $customerReferenceParam = 'paymentMethodToken'; + $deviceData = Input::get('device_data'); + if (!$deviceData) { + $deviceData = Session::get($invitation->id . 'device_data'); + } + + if($deviceData) { + $details['device_data'] = $deviceData; + } + } elseif ($accountGateway->gateway_id == GATEWAY_WEPAY) { + $tokenBillingSupported = true; + $customerReferenceParam = false; + } + + if ($tokenBillingSupported) { if ($useToken) { - $details['customerReference'] = $customerReference; - unset($details['token']); - $details['cardReference'] = $sourceReference; + if ($customerReferenceParam) { + $details[$customerReferenceParam] = $customerReference; + } + $details['token'] = $sourceReference; + unset($details['card']); } elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing') || $paymentType == PAYMENT_TYPE_STRIPE_ACH) { $token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */); if ($token) { $details['token'] = $token; - $details['customerReference'] = $customerReference; + if ($customerReferenceParam) { + $details[$customerReferenceParam] = $customerReference; + } if ($paymentType == PAYMENT_TYPE_STRIPE_ACH && empty(Input::get('plaidPublicToken')) ) { // The user needs to complete verification @@ -518,36 +547,6 @@ class PaymentController extends BaseController return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); } } - } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { - $deviceData = Input::get('device_data'); - if (!$deviceData) { - $deviceData = Session::get($invitation->id . 'device_data'); - } - - if ($token = Input::get('payment_method_nonce')) { - $details['token'] = $token; - unset($details['card']); - } - - if ($useToken) { - $details['customerId'] = $customerReference; - $details['paymentMethodToken'] = $sourceReference; - unset($details['token']); - } elseif ($account->token_billing_type_id == TOKEN_BILLING_ALWAYS || Input::get('token_billing')) { - $token = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id, $customerReference/* return parameter */, $paymentMethod/* return parameter */); - if ($token) { - $details['paymentMethodToken'] = $token; - $details['customerId'] = $customerReference; - unset($details['token']); - } else { - $this->error('Token-No-Ref', $this->paymentService->lastError, $accountGateway); - return Redirect::to('payment/'.$invitationKey)->withInput(Request::except('cvv')); - } - } - - if($deviceData) { - $details['deviceData'] = $deviceData; - } } $response = $gateway->purchase($details)->send(); diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index 405de63493b0..360f71e90fbf 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -859,7 +859,6 @@ class PublicClientController extends BaseController ]; if ($paymentType == PAYMENT_TYPE_STRIPE_ACH) { - $data['currencies'] = Cache::get('currencies'); } @@ -867,6 +866,10 @@ class PublicClientController extends BaseController $data['braintreeClientToken'] = $this->paymentService->getBraintreeClientToken($account); } + if(!empty($data['braintreeClientToken']) || $accountGateway->getPublishableStripeKey()|| $accountGateway->gateway_id == GATEWAY_WEPAY) { + $data['tokenize'] = true; + } + return View::make('payments.add_paymentmethod', $data); } @@ -882,7 +885,7 @@ class PublicClientController extends BaseController $account = $client->account; $accountGateway = $account->getGatewayByType($paymentType); - $sourceToken = $accountGateway->gateway_id == GATEWAY_STRIPE ? Input::get('stripeToken'):Input::get('payment_method_nonce'); + $sourceToken = Input::get('sourceToken'); if (!PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType)) { return Redirect::to('client/paymentmethods/add/' . $typeLink)->withInput(Request::except('cvv')); diff --git a/app/Http/routes.php b/app/Http/routes.php index 2c12c215cfd3..3a02960d8005 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -562,6 +562,10 @@ if (!defined('CONTACT_EMAIL')) { define('GATEWAY_WEPAY', 60); define('GATEWAY_BRAINTREE', 61); + // The customer exists, but only as a local concept + // The remote gateway doesn't understand the concept of customers + define('CUSTOMER_REFERENCE_LOCAL', 'local'); + define('EVENT_CREATE_CLIENT', 1); define('EVENT_CREATE_INVOICE', 2); define('EVENT_CREATE_QUOTE', 3); @@ -749,7 +753,7 @@ if (!defined('CONTACT_EMAIL')) { // WePay define('WEPAY_PRODUCTION', 'production'); - define('WEPAY_STAGING', 'staging'); + define('WEPAY_STAGE', 'stage'); define('WEPAY_CLIENT_ID', env('WEPAY_CLIENT_ID')); define('WEPAY_CLIENT_SECRET', env('WEPAY_CLIENT_SECRET')); define('WEPAY_ENVIRONMENT', env('WEPAY_ENVIRONMENT', WEPAY_PRODUCTION)); diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 8e54926e8045..dc92f6e65125 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -995,7 +995,7 @@ class Utils public static function setupWePay($accountGateway = null) { if (WePay::getEnvironment() == 'none') { - if (WEPAY_ENVIRONMENT == WEPAY_STAGING) { + if (WEPAY_ENVIRONMENT == WEPAY_STAGE) { WePay::useStaging(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET); } else { WePay::useProduction(WEPAY_CLIENT_ID, WEPAY_CLIENT_SECRET); diff --git a/app/Models/Account.php b/app/Models/Account.php index 29a9abbd09be..fb2c39b951db 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1245,6 +1245,8 @@ class Account extends Eloquent return GATEWAY_STRIPE; } elseif ($this->isGatewayConfigured(GATEWAY_BRAINTREE)) { return GATEWAY_BRAINTREE; + } elseif ($this->isGatewayConfigured(GATEWAY_WEPAY)) { + return GATEWAY_WEPAY; } else { return false; } diff --git a/app/Services/AccountGatewayService.php b/app/Services/AccountGatewayService.php index c21902c87374..fe5427b966bb 100644 --- a/app/Services/AccountGatewayService.php +++ b/app/Services/AccountGatewayService.php @@ -46,7 +46,7 @@ class AccountGatewayService extends BaseService return link_to("gateways/{$model->public_id}/edit", $model->name)->toHtml(); } else { $accountGateway = AccountGateway::find($model->id); - $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGING ? 'https://stage.wepay.com/' : 'https://www.wepay.com/'; + $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/'; $wepayAccountId = $accountGateway->getConfig()->accountId; $linkText = $model->name; $url = $endpoint.'account/'.$wepayAccountId; @@ -116,7 +116,7 @@ class AccountGatewayService extends BaseService uctrans('texts.manage_wepay_account'), function ($model) { $accountGateway = AccountGateway::find($model->id); - $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGING ? 'https://stage.wepay.com/' : 'https://www.wepay.com/'; + $endpoint = WEPAY_ENVIRONMENT == WEPAY_STAGE ? 'https://stage.wepay.com/' : 'https://www.wepay.com/'; return array( 'url' => $endpoint.'account/'.$accountGateway->getConfig()->accountId, 'attributes' => 'target="_blank"' diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index b97bbbd67de4..626366a469cd 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -9,6 +9,7 @@ use Cache; use Omnipay; use Session; use CreditCard; +use WePay; use App\Models\Payment; use App\Models\PaymentMethod; use App\Models\Account; @@ -30,7 +31,8 @@ class PaymentService extends BaseService protected static $refundableGateways = array( GATEWAY_STRIPE, - GATEWAY_BRAINTREE + GATEWAY_BRAINTREE, + GATEWAY_WEPAY, ); public function __construct(PaymentRepository $paymentRepo, AccountRepository $accountRepo, DatatableService $datatableService) @@ -95,9 +97,9 @@ class PaymentService extends BaseService $data['ButtonSource'] = 'InvoiceNinja_SP'; }; - if ($input && $accountGateway->isGateway(GATEWAY_STRIPE)) { - if (!empty($input['stripeToken'])) { - $data['token'] = $input['stripeToken']; + if ($input) { + if (!empty($input['sourceToken'])) { + $data['token'] = $input['sourceToken']; unset($data['card']); } elseif (!empty($input['plaidPublicToken'])) { $data['plaidPublicToken'] = $input['plaidPublicToken']; @@ -106,6 +108,10 @@ class PaymentService extends BaseService } } + if ($accountGateway->isGateway(GATEWAY_WEPAY) && $transactionId = Session::get($invitation->id.'payment_ref')) { + $data['transaction_id'] = $transactionId; + } + return $data; } @@ -266,6 +272,17 @@ class PaymentService extends BaseService if (!$response->isSuccessful()) { return $response->getMessage(); } + } elseif ($accountGateway->gateway_id == GATEWAY_WEPAY) { + try { + $wepay = Utils::setupWePay($accountGateway); + $wepay->request('/credit_card/delete', [ + 'client_id' => WEPAY_CLIENT_ID, + 'client_secret' => WEPAY_CLIENT_SECRET, + 'credit_card_id' => $paymentMethod->source_reference, + ]); + } catch (\WePayException $ex){ + return $ex->getMessage(); + } } $paymentMethod->delete(); @@ -291,16 +308,16 @@ class PaymentService extends BaseService { $customerReference = $client->getGatewayToken($accountGateway, $accountGatewayToken/* return paramenter */); - if ($customerReference) { + if ($customerReference && $customerReference != CUSTOMER_REFERENCE_LOCAL) { $details['customerReference'] = $customerReference; - if ($accountGateway->gateway->id == GATEWAY_STRIPE) { + if ($accountGateway->gateway_id == GATEWAY_STRIPE) { $customerResponse = $gateway->fetchCustomer(array('customerReference' => $customerReference))->send(); if (!$customerResponse->isSuccessful()) { $customerReference = null; // The customer might not exist anymore } - } elseif ($accountGateway->gateway->id == GATEWAY_BRAINTREE) { + } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { $customer = $gateway->findCustomer($customerReference)->send()->getData(); if (!($customer instanceof \Braintree\Customer)) { @@ -309,7 +326,7 @@ class PaymentService extends BaseService } } - if ($accountGateway->gateway->id == GATEWAY_STRIPE) { + if ($accountGateway->gateway_id == GATEWAY_STRIPE) { if (!empty($details['plaidPublicToken'])) { $plaidResult = $this->getPlaidToken($accountGateway, $details['plaidPublicToken'], $details['plaidAccountId']); @@ -355,7 +372,7 @@ class PaymentService extends BaseService return; } } - } elseif ($accountGateway->gateway->id == GATEWAY_BRAINTREE) { + } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { if (!$customerReference) { $tokenResponse = $gateway->createCustomer(array('customerData' => array()))->send(); if ($tokenResponse->isSuccessful()) { @@ -377,6 +394,31 @@ class PaymentService extends BaseService return; } } + } elseif ($accountGateway->gateway_id == GATEWAY_WEPAY) { + $wepay = Utils::setupWePay($accountGateway); + + try { + $wepay->request('credit_card/authorize', array( + 'client_id' => WEPAY_CLIENT_ID, + 'client_secret' => WEPAY_CLIENT_SECRET, + 'credit_card_id' => $details['token'], + )); + + // Get the card details + $tokenResponse = $wepay->request('credit_card', array( + 'client_id' => WEPAY_CLIENT_ID, + 'client_secret' => WEPAY_CLIENT_SECRET, + 'credit_card_id' => $details['token'], + )); + + $customerReference = CUSTOMER_REFERENCE_LOCAL; + $sourceReference = $details['token']; + } catch (\WePayException $ex) { + $this->lastError = $ex->getMessage(); + return; + } + } else { + return null; } if ($customerReference) { @@ -394,7 +436,7 @@ class PaymentService extends BaseService $accountGatewayToken->token = $customerReference; $accountGatewayToken->save(); - $paymentMethod = $this->createPaymentMethodFromGatewayResponse($tokenResponse, $accountGateway, $accountGatewayToken, $contactId); + $paymentMethod = $this->convertPaymentMethodFromGatewayResponse($tokenResponse, $accountGateway, $accountGatewayToken, $contactId); } else { $this->lastError = $tokenResponse->getMessage(); @@ -456,8 +498,24 @@ class PaymentService extends BaseService return $paymentMethod; } + + public function convertPaymentMethodFromWePay($source, $accountGatewayToken = null, $paymentMethod = null) { + // Creating a new one or updating an existing one + if (!$paymentMethod) { + $paymentMethod = $accountGatewayToken ? PaymentMethod::createNew($accountGatewayToken) : new PaymentMethod(); + } + + $paymentMethod->payment_type_id = $this->parseCardType($source->credit_card_name); + $paymentMethod->last4 = $source->last_four; + $paymentMethod->expiration = $source->expiration_year . '-' . $source->expiration_month . '-00'; + $paymentMethod->setRelation('payment_type', Cache::get('paymentTypes')->find($paymentMethod->payment_type_id)); + + $paymentMethod->source_reference = $source->credit_card_id; + + return $paymentMethod; + } - public function createPaymentMethodFromGatewayResponse($gatewayResponse, $accountGateway, $accountGatewayToken = null, $contactId = null) { + public function convertPaymentMethodFromGatewayResponse($gatewayResponse, $accountGateway, $accountGatewayToken = null, $contactId = null, $existingPaymentMethod = null) { if ($accountGateway->gateway_id == GATEWAY_STRIPE) { $data = $gatewayResponse->getData(); if (!empty($data['object']) && ($data['object'] == 'card' || $data['object'] == 'bank_account')) { @@ -470,7 +528,7 @@ class PaymentService extends BaseService } if ($source) { - $paymentMethod = $this->convertPaymentMethodFromStripe($source, $accountGatewayToken); + $paymentMethod = $this->convertPaymentMethodFromStripe($source, $accountGatewayToken, $existingPaymentMethod); } } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { $data = $gatewayResponse->getData(); @@ -478,7 +536,12 @@ class PaymentService extends BaseService if (!empty($data->transaction)) { $transaction = $data->transaction; - $paymentMethod = $accountGatewayToken ? PaymentMethod::createNew($accountGatewayToken) : new PaymentMethod(); + if ($existingPaymentMethod) { + $paymentMethod = $existingPaymentMethod; + } else { + $paymentMethod = $accountGatewayToken ? PaymentMethod::createNew($accountGatewayToken) : new PaymentMethod(); + } + if ($transaction->paymentInstrumentType == 'credit_card') { $card = $transaction->creditCardDetails; $paymentMethod->last4 = $card->last4; @@ -490,9 +553,20 @@ class PaymentService extends BaseService } $paymentMethod->setRelation('payment_type', Cache::get('paymentTypes')->find($paymentMethod->payment_type_id)); } elseif (!empty($data->paymentMethod)) { - $paymentMethod = $this->convertPaymentMethodFromBraintree($data->paymentMethod, $accountGatewayToken); + $paymentMethod = $this->convertPaymentMethodFromBraintree($data->paymentMethod, $accountGatewayToken, $existingPaymentMethod); } + } elseif ($accountGateway->gateway_id == GATEWAY_WEPAY) { + if ($gatewayResponse instanceof \Omnipay\WePay\Message\CustomCheckoutResponse) { + $wepay = \Utils::setupWePay($accountGateway); + $gatewayResponse = $wepay->request('credit_card', array( + 'client_id' => WEPAY_CLIENT_ID, + 'client_secret' => WEPAY_CLIENT_SECRET, + 'credit_card_id' => $gatewayResponse->getData()['payment_method']['credit_card']['id'], + )); + + } + $paymentMethod = $this->convertPaymentMethodFromWePay($gatewayResponse, $accountGatewayToken, $existingPaymentMethod); } if (!empty($paymentMethod) && $accountGatewayToken && $contactId) { @@ -566,43 +640,49 @@ class PaymentService extends BaseService $payment->payment_type_id = $this->detectCardType($card->getNumber()); } + $savePaymentMethod = !empty($paymentMethod); + + // This will convert various gateway's formats to a known format + $paymentMethod = $this->convertPaymentMethodFromGatewayResponse($purchaseResponse, $accountGateway, null, null, $paymentMethod); + + // If this is a stored payment method, we'll update it with the latest info + if ($savePaymentMethod) { + $paymentMethod->save(); + } + if ($accountGateway->gateway_id == GATEWAY_STRIPE) { $data = $purchaseResponse->getData(); - $source = !empty($data['source'])?$data['source']:$data['card']; - $payment->payment_status_id = $data['status'] == 'succeeded' ? PAYMENT_STATUS_COMPLETED : PAYMENT_STATUS_PENDING; - - if ($source) { - $payment->last4 = $source['last4']; - - if ($source['object'] == 'bank_account') { - $payment->routing_number = $source['routing_number']; - $payment->payment_type_id = PAYMENT_TYPE_ACH; - } - else{ - $payment->expiration = $source['exp_year'] . '-' . $source['exp_month'] . '-00'; - $payment->payment_type_id = $this->parseCardType($source['brand']); - } - } - } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { - $transaction = $purchaseResponse->getData()->transaction; - if ($transaction->paymentInstrumentType == 'credit_card') { - $card = $transaction->creditCardDetails; - $payment->last4 = $card->last4; - $payment->expiration = $card->expirationYear . '-' . $card->expirationMonth . '-00'; - $payment->payment_type_id = $this->parseCardType($card->cardType); - } elseif ($transaction->paymentInstrumentType == 'paypal_account') { - $payment->payment_type_id = PAYMENT_TYPE_ID_PAYPAL; - $payment->email = $transaction->paypalDetails->payerEmail; - } - } - - if ($payerId) { - $payment->payer_id = $payerId; } if ($paymentMethod) { - $payment->payment_method_id = $paymentMethod->id; + if ($paymentMethod->last4) { + $payment->last4 = $paymentMethod->last4; + } + + if ($paymentMethod->expiration) { + $payment->expiration = $paymentMethod->expiration; + } + + if ($paymentMethod->routing_number) { + $payment->routing_number = $paymentMethod->routing_number; + } + + if ($paymentMethod->payment_type_id) { + $payment->payment_type_id = $paymentMethod->payment_type_id; + } + + if ($paymentMethod->email) { + $payment->email = $paymentMethod->email; + } + + if ($payerId) { + $payment->payer_id = $payerId; + } + + if ($savePaymentMethod) { + $payment->payment_method_id = $paymentMethod->id; + } } $payment->save(); @@ -665,20 +745,29 @@ class PaymentService extends BaseService private function parseCardType($cardName) { $cardTypes = array( - 'Visa' => PAYMENT_TYPE_VISA, - 'American Express' => PAYMENT_TYPE_AMERICAN_EXPRESS, - 'MasterCard' => PAYMENT_TYPE_MASTERCARD, - 'Discover' => PAYMENT_TYPE_DISCOVER, - 'JCB' => PAYMENT_TYPE_JCB, - 'Diners Club' => PAYMENT_TYPE_DINERS, - 'Carte Blanche' => PAYMENT_TYPE_CARTE_BLANCHE, - 'China UnionPay' => PAYMENT_TYPE_UNIONPAY, - 'Laser' => PAYMENT_TYPE_LASER, - 'Maestro' => PAYMENT_TYPE_MAESTRO, - 'Solo' => PAYMENT_TYPE_SOLO, - 'Switch' => PAYMENT_TYPE_SWITCH + 'visa' => PAYMENT_TYPE_VISA, + 'americanexpress' => PAYMENT_TYPE_AMERICAN_EXPRESS, + 'amex' => PAYMENT_TYPE_AMERICAN_EXPRESS, + 'mastercard' => PAYMENT_TYPE_MASTERCARD, + 'discover' => PAYMENT_TYPE_DISCOVER, + 'jcb' => PAYMENT_TYPE_JCB, + 'dinersclub' => PAYMENT_TYPE_DINERS, + 'carteblanche' => PAYMENT_TYPE_CARTE_BLANCHE, + 'chinaunionpay' => PAYMENT_TYPE_UNIONPAY, + 'unionpay' => PAYMENT_TYPE_UNIONPAY, + 'laser' => PAYMENT_TYPE_LASER, + 'maestro' => PAYMENT_TYPE_MAESTRO, + 'solo' => PAYMENT_TYPE_SOLO, + 'switch' => PAYMENT_TYPE_SWITCH ); + $cardName = strtolower(str_replace(array(' ', '-', '_'), '', $cardName)); + + if (empty($cardTypes[$cardName]) && 1 == preg_match('/^('.implode('|', array_keys($cardTypes)).')/', $cardName, $matches)) { + // Some gateways return extra stuff after the card name + $cardName = $matches[1]; + } + if (!empty($cardTypes[$cardName])) { return $cardTypes[$cardName]; } else { @@ -736,10 +825,9 @@ class PaymentService extends BaseService $details = $this->getPaymentDetails($invitation, $accountGateway); $details['customerReference'] = $token; - if ($accountGateway->gateway_id == GATEWAY_STRIPE) { - $details['cardReference'] = $defaultPaymentMethod->source_reference; - } elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) { - $details['paymentMethodToken'] = $defaultPaymentMethod->source_reference; + $details['token'] = $defaultPaymentMethod->source_reference; + if ($accountGateway->gateway_id == GATEWAY_WEPAY) { + $details['transaction_id'] = 'autobill_'.$invoice->id; } // submit purchase/get response diff --git a/resources/views/payments/add_paymentmethod.blade.php b/resources/views/payments/add_paymentmethod.blade.php index 7c5ca2b956cf..e4d5d3c0a590 100644 --- a/resources/views/payments/add_paymentmethod.blade.php +++ b/resources/views/payments/add_paymentmethod.blade.php @@ -3,221 +3,11 @@ @section('head') @parent @if (!empty($braintreeClientToken)) - - + @include('payments.tokenization_braintree') @elseif (isset($accountGateway) && $accountGateway->getPublishableStripeKey()) - - + @include('payments.tokenization_stripe') + @elseif (isset($accountGateway) && $accountGateway->gateway_id == GATEWAY_WEPAY) + @include('payments.tokenization_wepay') @else @endif - @stop @section('content') @@ -283,7 +72,6 @@ {{ Former::populateField('email', $contact->email) }} @if (!$client->country_id && $client->account->country_id) {{ Former::populateField('country_id', $client->account->country_id) }} - {{ Former::populateField('country', $client->account->country->iso_3166_2) }} @endif @if (!$client->currency_id && $client->account->currency_id) {{ Former::populateField('currency_id', $client->account->currency_id) }} @@ -442,9 +230,9 @@ ))->inline()->label(trans('texts.account_holder_type')); !!} {!! Former::text('account_holder_name') ->label(trans('texts.account_holder_name')) !!} - {!! Former::select('country') + {!! Former::select('country_id') ->label(trans('texts.country_id')) - ->fromQuery($countries, 'name', 'iso_3166_2') + ->fromQuery($countries, 'name', 'id') ->addGroupClass('country-select') !!} {!! Former::select('currency') ->label(trans('texts.currency_id')) @@ -485,7 +273,7 @@

{{ trans('texts.paypal') }}

{{$paypalDetails->firstName}} {{$paypalDetails->lastName}}
{{$paypalDetails->email}}
- + @@ -515,7 +303,7 @@ @if (!empty($braintreeClientToken))
@else - {!! Former::text($accountGateway->getPublishableStripeKey() ? '' : 'card_number') + {!! Former::text(!empty($tokenize) ? '' : 'card_number') ->id('card_number') ->placeholder(trans('texts.card_number')) ->autocomplete('cc-number') @@ -526,7 +314,7 @@ @if (!empty($braintreeClientToken))
@else - {!! Former::text($accountGateway->getPublishableStripeKey() ? '' : 'cvv') + {!! Former::text(!empty($tokenize) ? '' : 'cvv') ->id('cvv') ->placeholder(trans('texts.cvv')) ->autocomplete('off') @@ -539,7 +327,7 @@ @if (!empty($braintreeClientToken))
@else - {!! Former::select($accountGateway->getPublishableStripeKey() ? '' : 'expiration_month') + {!! Former::select(!empty($tokenize) ? '' : 'expiration_month') ->id('expiration_month') ->autocomplete('cc-exp-month') ->placeholder(trans('texts.expiration_month')) @@ -562,7 +350,7 @@ @if (!empty($braintreeClientToken))
@else - {!! Former::select($accountGateway->getPublishableStripeKey() ? '' : 'expiration_year') + {!! Former::select(!empty($tokenize) ? '' : 'expiration_year') ->id('expiration_year') ->autocomplete('cc-exp-year') ->placeholder(trans('texts.expiration_year')) diff --git a/resources/views/payments/paymentmethods_list.blade.php b/resources/views/payments/paymentmethods_list.blade.php index 0dc04a988e58..79e8faae5bd1 100644 --- a/resources/views/payments/paymentmethods_list.blade.php +++ b/resources/views/payments/paymentmethods_list.blade.php @@ -183,5 +183,6 @@ function setDefault(sourceId) { $('#default_id').val(sourceId); $('#defaultSourceForm').submit() + return false; } \ No newline at end of file diff --git a/resources/views/payments/tokenization_braintree.blade.php b/resources/views/payments/tokenization_braintree.blade.php new file mode 100644 index 000000000000..f6f6e5921706 --- /dev/null +++ b/resources/views/payments/tokenization_braintree.blade.php @@ -0,0 +1,61 @@ + + \ No newline at end of file diff --git a/resources/views/payments/tokenization_stripe.blade.php b/resources/views/payments/tokenization_stripe.blade.php new file mode 100644 index 000000000000..325393061866 --- /dev/null +++ b/resources/views/payments/tokenization_stripe.blade.php @@ -0,0 +1,154 @@ + + \ No newline at end of file diff --git a/resources/views/payments/tokenization_wepay.blade.php b/resources/views/payments/tokenization_wepay.blade.php new file mode 100644 index 000000000000..4f130d69e01b --- /dev/null +++ b/resources/views/payments/tokenization_wepay.blade.php @@ -0,0 +1,52 @@ + + \ No newline at end of file