Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkIncognito85 committed Jan 16, 2022
1 parent 90acfa2 commit 45fe2fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/Stripe/Api/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public function getCustomer(string $customerId): Customer
return $this->stripe->customers->retrieve($customerId);
}


public function checkConnection()
{
$this->stripe->customers->all(['limit' => 1]);
}

public function getInvoice(string $invoice): Invoice
{
return $this->stripe->invoices->retrieve($invoice);
Expand Down
9 changes: 9 additions & 0 deletions src/Stripe/StripePaymentBoard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace App\Stripe;

class StripePaymentBoard extends \App\Shop\Payment\AbstractPaymentBoard
{
protected string $entity = StripePaymentType::class;
protected string $type = 'stripe';
}
29 changes: 21 additions & 8 deletions src/Stripe/StripePaymentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function process(Transaction $transaction, Request $request, User $user)
'price_data' =>
[
'currency' => $transaction->getCurrency(),
'unit_amount' => $item->priceWithTax() * 100,
'unit_amount' => round($item->priceWithTax() * 100),
'product_data' => ["name" => $item->getName()]
],
'quantity' => $item->getQuantity(),
Expand Down Expand Up @@ -92,7 +92,7 @@ public function execute(Transaction $transaction, Request $request, User $user)

}

public function confirm(Transaction $transaction, Request $request, User $user){
public function test(Transaction $transaction, Request $request, User $user){
$params = $request->getServerParams();
$signature = $params["HTTP_STRIPE_SIGNATURE"];
$webhook = $this->stripe->getWebhook($signature);
Expand All @@ -108,24 +108,37 @@ public function confirm(Transaction $transaction, Request $request, User $user){
$this->service->changeState($transaction);
$this->service->setReason($transaction);
} else {
$this->service->complete($transaction);

if ($this->service->isOrder($transaction)) {
$this->service->confirmOrder($transaction, $user->getId());
}
$transaction->setState($transaction::COMPLETED);
$this->service->changeState($transaction);
return $transaction;
}
} else if ($webhook->type === 'payment_intent.succeeded') {

$object = $webhook->data->object;
$id = $webhook->id;
$transaction->setTransactionId($id);
$this->service->updateTransactionId($transaction);
return $transaction;

}
}

public function success(Request $request){
public function confirm(Request $request)
{
$params = $request->getServerParams();
$signature = $params["HTTP_STRIPE_SIGNATURE"];
$webhook = $this->stripe->getWebhook($signature);
if ($webhook->type === 'payment_intent.succeeded'){

if ($webhook->type === 'payment_intent.succeeded') {
$transaction = $this->service->getLastTransaction();
$id = $webhook->id;

$object = $webhook->data->object;
$id = $object->id;
$transaction->setTransactionId($id);
$this->service->updateTransactionId($transaction);
return $transaction;
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/Stripe/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
use function DI\get;

return [
'auth.entity' => StripeUser::class,
'payments.type' => add(get(StripePaymentType::class)),
'csrf.except' => add(['stripe.webhook']),
Stripe::class => autowire()
'auth.entity' => StripeUser::class,
'payments.type' => add(get(StripePaymentType::class)),
'csrf.except' => add(['stripe.webhook']),
'payment.boards' => add(get(StripePaymentType::class)),
Stripe::class => autowire()
->constructorParameter('endpointkey', $_ENV['STRIPE_ENDPOINT'] ?? null)
->constructorParameter('privateKey', $_ENV['STRIPE_SECRET'] ?? null)
->constructorParameter('publicKey', $_ENV['STRIPE_PUBLIC'] ?? null)
Expand Down

0 comments on commit 45fe2fa

Please sign in to comment.