diff --git a/app/PaymentDrivers/Stripe/ApplePay.php b/app/PaymentDrivers/Stripe/ApplePay.php new file mode 100644 index 000000000000..3b32ede65b7e --- /dev/null +++ b/app/PaymentDrivers/Stripe/ApplePay.php @@ -0,0 +1,91 @@ +stripe_driver = $stripe_driver; + } + + public function paymentView(array $data) + { + $data['gateway'] = $this->stripe_driver; + $data['payment_hash'] = $this->stripe_driver->payment_hash->hash; + $data['payment_method_id'] = GatewayType::APPLE_PAY; + $data['country'] = $this->stripe_driver->client->country; + $data['currency'] = $this->stripe_driver->client->currency()->code; + $data['stripe_amount'] = $this->stripe_driver->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe_driver->client->currency()->precision, $this->stripe_driver->client->currency()); + $data['invoices'] = $this->stripe_driver->payment_hash->invoices(); + + $data['intent'] = \Stripe\PaymentIntent::create([ + 'amount' => $data['stripe_amount'], + 'currency' => $this->stripe_driver->client->getCurrencyCode();, + ], $this->stripe_driver->stripe_connect_auth); + + $this->stripe_driver->payment_hash->data = array_merge((array) $this->stripe_driver->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]); + $this->stripe_driver->payment_hash->save(); + + return render('gateways.stripe.applepay.pay', $data); + } + + + public function paymentResponse(PaymentResponseRequest $request) + { + + $this->stripe_driver->init(); + + $state = [ + 'server_response' => json_decode($request->gateway_response), + 'payment_hash' => $request->payment_hash, + ]; + + $state['payment_intent'] = \Stripe\PaymentIntent::retrieve($state['server_response']->id, $this->stripe_driver->stripe_connect_auth); + + $state['customer'] = $state['payment_intent']->customer; + + $this->stripe_driver->payment_hash->data = array_merge((array) $this->stripe_driver->payment_hash->data, $state); + $this->stripe_driver->payment_hash->save(); + + $server_response = $this->stripe_driver->payment_hash->data->server_response; + + $response_handler = new CreditCard($this->stripe_driver); + + if ($server_response->status == 'succeeded') { + + $this->stripe_driver->logSuccessfulGatewayResponse(['response' => json_decode($request->gateway_response), 'data' => $this->stripe_driver->payment_hash], SystemLog::TYPE_STRIPE); + + return $response_handler->processSuccessfulPayment(); + } + + return $response_handler->processUnsuccessfulPayment($server_response); + + + } + +} diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index 72981fea3013..cdb36d8d3557 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -108,7 +108,7 @@ class CreditCard return $this->processUnsuccessfulPayment($server_response); } - private function processSuccessfulPayment() + public function processSuccessfulPayment() { $stripe_method = $this->stripe->getStripePaymentMethod($this->stripe->payment_hash->data->server_response->payment_method); @@ -148,7 +148,7 @@ class CreditCard return redirect()->route('client.payments.show', ['payment' => $this->stripe->encodePrimaryKey($payment->id)]); } - private function processUnsuccessfulPayment($server_response) + public function processUnsuccessfulPayment($server_response) { PaymentFailureMailer::dispatch($this->stripe->client, $server_response->cancellation_reason, $this->stripe->client->company, $server_response->amount); diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index f792ce495422..7ad6f87062c2 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -25,6 +25,7 @@ use App\Models\PaymentHash; use App\Models\SystemLog; use App\PaymentDrivers\Stripe\ACH; use App\PaymentDrivers\Stripe\Alipay; +use App\PaymentDrivers\Stripe\ApplePay; use App\PaymentDrivers\Stripe\Charge; use App\PaymentDrivers\Stripe\Connect\Verify; use App\PaymentDrivers\Stripe\CreditCard; @@ -72,7 +73,7 @@ class StripePaymentDriver extends BaseDriver GatewayType::BANK_TRANSFER => ACH::class, GatewayType::ALIPAY => Alipay::class, GatewayType::SOFORT => SOFORT::class, - GatewayType::APPLE_PAY => 1, // TODO + GatewayType::APPLE_PAY => ApplePay::class, GatewayType::SEPA => 1, // TODO ]; diff --git a/resources/views/portal/ninja2020/gateways/stripe/applepay/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/applepay/pay.blade.php new file mode 100644 index 000000000000..3ef1568f6dd3 --- /dev/null +++ b/resources/views/portal/ninja2020/gateways/stripe/applepay/pay.blade.php @@ -0,0 +1,112 @@ +@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'Alipay', 'card_title' => 'Alipay']) + +@section('gateway_head') + +@endsection + +@section('gateway_content') +
+ @csrf + + + + +
+ + + + @include('portal.ninja2020.gateways.includes.payment_details') + +
+ +
+ +@endsection + +@push('footer') + + + +@endpush \ No newline at end of file