mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-30 20:22:58 -04:00 
			
		
		
		
	Extract paymentView
This commit is contained in:
		
							parent
							
								
									cf503b4531
								
							
						
					
					
						commit
						b589814d7b
					
				| @ -95,9 +95,11 @@ class PaymentController extends Controller | ||||
|             return $invoice; | ||||
|         }); | ||||
| 
 | ||||
|         $invoices->each(function ($invoice) { | ||||
|             InjectSignature::dispatch($invoice, request()->signature); | ||||
|         }); | ||||
|         if ((bool) request()->signature) { | ||||
|             $invoices->each(function ($invoice) { | ||||
|                 InjectSignature::dispatch($invoice, request()->signature); | ||||
|             }); | ||||
|         } | ||||
| 
 | ||||
|         $payment_methods = auth()->user()->client->getPaymentMethods($amount); | ||||
|         $gateway = CompanyGateway::find(request()->input('company_gateway_id')); | ||||
| @ -116,7 +118,10 @@ class PaymentController extends Controller | ||||
|             'hashed_ids' => request()->invoices, | ||||
|         ]; | ||||
| 
 | ||||
|         return $gateway->driver(auth()->user()->client)->processPaymentView($data); | ||||
|         return $gateway | ||||
|             ->driver(auth()->user()->client) | ||||
|             ->setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard') | ||||
|             ->processPaymentView($data); | ||||
|     } | ||||
| 
 | ||||
|     public function response(Request $request) | ||||
|  | ||||
| @ -68,7 +68,7 @@ class CreditCard | ||||
|         $client_gateway_token->save(); | ||||
| 
 | ||||
|         if ($is_default == 'true' || $this->stripe->client->gateway_tokens->count() == 1) { | ||||
|             $this->stripe->client->gateway_tokens()->update(['is_default'=>0]); | ||||
|             $this->stripe->client->gateway_tokens()->update(['is_default' => 0]); | ||||
| 
 | ||||
|             $client_gateway_token->is_default = 1; | ||||
|             $client_gateway_token->save(); | ||||
| @ -76,4 +76,32 @@ class CreditCard | ||||
| 
 | ||||
|         return redirect()->route('client.payment_methods.index'); | ||||
|     } | ||||
| 
 | ||||
|     public function paymentView(array $data) | ||||
|     { | ||||
|         $payment_intent_data = [ | ||||
|             'amount' => $this->stripe->convertToStripeAmount($data['amount_with_fee'], $this->stripe->client->currency()->precision), | ||||
|             'currency' => $this->stripe->client->getCurrencyCode(), | ||||
|             'customer' => $this->stripe->findOrCreateCustomer(), | ||||
|             'description' => $data['invoices']->pluck('id'), //todo more meaningful description here:
 | ||||
|         ]; | ||||
| 
 | ||||
|         if ($data['token']) { | ||||
|             $payment_intent_data['payment_method'] = $data['token']->token; | ||||
|         } else { | ||||
|             $payment_intent_data['setup_future_usage']  = 'off_session'; | ||||
|             // $payment_intent_data['save_payment_method'] = true;
 | ||||
|             // $payment_intent_data['confirm'] = true;
 | ||||
|         } | ||||
| 
 | ||||
|         $data['intent'] = $this->stripe->createPaymentIntent($payment_intent_data); | ||||
|         $data['gateway'] = $this->stripe; | ||||
| 
 | ||||
|         return render('gateways.stripe.credit_card', $data); | ||||
|     } | ||||
| 
 | ||||
|     public function paymentResponse() | ||||
|     { | ||||
|         # code...
 | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -65,12 +65,6 @@ class StripePaymentDriver extends BasePaymentDriver | ||||
|         Stripe::setApiKey($this->company_gateway->getConfigField('apiKey')); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Return payment method type. | ||||
|      *  | ||||
|      * @param string $method  | ||||
|      * @return $this  | ||||
|      */ | ||||
|     public function setPaymentMethod(string $method) | ||||
|     { | ||||
|         // Example: setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard');
 | ||||
| @ -160,9 +154,9 @@ class StripePaymentDriver extends BasePaymentDriver | ||||
|     /** | ||||
|      * Processes the gateway response for credit card authorization. | ||||
|      * | ||||
|      * @param Request $request The returning request object | ||||
|      * @return view          Returns the user to payment methods screen. | ||||
|      * @throws \Stripe\Exception\ApiErrorException | ||||
|      * @param \Illuminate\Http\Request $request The returning request object | ||||
| 
 | ||||
|      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||||
|      */ | ||||
|     public function authorizeCreditCardResponse($request) | ||||
|     { | ||||
| @ -173,11 +167,13 @@ class StripePaymentDriver extends BasePaymentDriver | ||||
|      * Process the payment with gateway. | ||||
|      * | ||||
|      * @param array $data | ||||
| 
 | ||||
|      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|void | ||||
|      * @throws \Exception | ||||
|      */ | ||||
|     public function processPaymentView(array $data) | ||||
|     { | ||||
|         return $this->payment_method->paymentView($data); | ||||
| 
 | ||||
|         $payment_intent_data = [ | ||||
|             'amount' => $this->convertToStripeAmount($data['amount_with_fee'], $this->client->currency()->precision), | ||||
|             'currency' => $this->client->getCurrencyCode(), | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user