Working on Alipay

This commit is contained in:
Hillel Coren 2017-09-04 13:14:58 +03:00
parent e6cad704ef
commit e87f2def1d
7 changed files with 74 additions and 1 deletions

View File

@ -414,6 +414,7 @@ if (! defined('APP_NAME')) {
define('GATEWAY_TYPE_BITCOIN', 4);
define('GATEWAY_TYPE_DWOLLA', 5);
define('GATEWAY_TYPE_CUSTOM', 6);
define('GATEWAY_TYPE_ALIPAY', 7);
define('GATEWAY_TYPE_TOKEN', 'token');
define('TEMPLATE_INVOICE', 'invoice');

View File

@ -130,6 +130,10 @@ class ClientPortalController extends BaseController
if ($wepayGateway = $account->getGatewayConfig(GATEWAY_WEPAY)) {
$data['enableWePayACH'] = $wepayGateway->getAchEnabled();
}
if ($stripeGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) {
//$data['enableStripeSources'] = $stripeGateway->getAlipayEnabled();
$data['enableStripeSources'] = true;
}
$showApprove = $invoice->quote_invoice_id ? false : true;
if ($invoice->due_date) {

View File

@ -198,6 +198,33 @@ class OnlinePaymentController extends BaseController
}
}
public function createSource($invitationKey, $gatewayType)
{
if (! $invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) {
return response()->view('error', [
'error' => trans('texts.invoice_not_found'),
'hideHeader' => true,
]);
}
$gatewayTypeId = GatewayType::getIdFromAlias($gatewayType);
$paymentDriver = $invitation->account->paymentDriver($invitation, $gatewayTypeId);
return $paymentDriver->createSource();
}
public function completeSource($invitationKey, $gatewayType)
{
if (! $invitation = $this->invoiceRepo->findInvoiceByInvitation($invitationKey)) {
return response()->view('error', [
'error' => trans('texts.invoice_not_found'),
'hideHeader' => true,
]);
}
return redirect()->to('view/' . $invitation->invitation_key);
}
/**
* @param $paymentDriver
* @param $exception

View File

@ -33,6 +33,8 @@ Route::group(['middleware' => ['lookup:contact', 'auth:client']], function () {
Route::get('approve/{invitation_key}', 'QuoteController@approve');
Route::get('payment/{invitation_key}/{gateway_type?}/{source_id?}', 'OnlinePaymentController@showPayment');
Route::post('payment/{invitation_key}', 'OnlinePaymentController@doPayment');
Route::get('create_source/{invitation_key}/{gateway_type}', 'OnlinePaymentController@createSource');
Route::get('complete_source/{invitation_key}/{gateway_type}', 'OnlinePaymentController@completeSource');
Route::match(['GET', 'POST'], 'complete/{invitation_key?}/{gateway_type?}', 'OnlinePaymentController@offsitePayment');
Route::get('bank/{routing_number}', 'OnlinePaymentController@getBankInfo');
Route::get('client/payment_methods', 'ClientPortalController@paymentMethods');

View File

@ -144,6 +144,18 @@ class AccountGateway extends EntityModel
return ! empty($this->getConfigField('enableAch'));
}
/**
* @return bool
*/
public function getAlipayEnabled()
{
if (\Utils::isNinjaDev()) {
return true;
}
return ! empty($this->getConfigField('enableAlipay'));
}
/**
* @return bool
*/

View File

@ -4,6 +4,7 @@ namespace App\Ninja\PaymentDrivers;
use App\Models\Payment;
use App\Models\PaymentMethod;
use App\Models\GatewayType;
use Cache;
use Exception;
use App\Models\PaymentType;
@ -24,6 +25,10 @@ class StripePaymentDriver extends BasePaymentDriver
$types[] = GATEWAY_TYPE_BANK_TRANSFER;
}
if ($this->accountGateway && $this->accountGateway->getAlipayEnabled()) {
$types[] = GATEWAY_TYPE_ALIPAY;
}
return $types;
}
@ -308,6 +313,23 @@ class StripePaymentDriver extends BasePaymentDriver
return true;
}
public function createSource()
{
$amount = intval($this->invoice()->getRequestedAmount() * 100);
$currency = $this->client()->getCurrencyCode();
$gatewayType = GatewayType::getAliasFromId($this->gatewayType);
$redirect = url("/complete_source/{$this->invitation->invitation_key}/{$gatewayType}");
$email = $this->contact()->email;
$data = "type=alipay&amount={$amount}&currency={$currency}&redirect[return_url]={$redirect}&owner[email]={$email}";
$response = $this->makeStripeCall('POST', 'sources', $data);
$this->invitation->transaction_reference = $response['id'];
$this->invitation->save();
return redirect($response['redirect']['url']);
}
public function makeStripeCall($method, $url, $body = null)
{
$apiKey = $this->accountGateway->getConfig()->apiKey;
@ -347,6 +369,10 @@ class StripePaymentDriver extends BasePaymentDriver
public function handleWebHook($input)
{
if (\Utils::isNinjaDev()) {
\Log::info("WEB HOOK: {$eventType} {$eventId}");
}
$eventId = array_get($input, 'id');
$eventType = array_get($input, 'type');

View File

@ -15,6 +15,7 @@ class GatewayTypesSeeder extends Seeder
['alias' => 'bitcoin', 'name' => 'Bitcoin'],
['alias' => 'dwolla', 'name' => 'Dwolla'],
['alias' => 'custom', 'name' => 'Custom'],
['alias' => 'alipay', 'name' => 'Alipay'],
];
foreach ($gateway_types as $gateway_type) {