Skip to content
Code-Schnipsel Gruppen Projekte
Bestätigt Commit 4f40b459 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

feat: compatiblity to payments v2

Übergeordneter 8029f48b
No related branches found
No related tags found
2 Merge Requests!4Next,!3feat: compatiblity to payments v2
Pipeline #5252 mit Warnungen bestanden mit Phase
in 12 Sekunden
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"url": "http:\/\/www.pcsg.de" "url": "http:\/\/www.pcsg.de"
}, },
"require": { "require": {
"quiqqer\/payments": "^1.1|dev-master|dev-dev", "quiqqer\/payments": "^2|^1.1|dev-master|dev-dev",
"stripe\/stripe-php": "^7", "stripe\/stripe-php": "^7",
"cbschuld\/browser.php": "^1" "cbschuld\/browser.php": "^1"
}, },
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
use QUI; use QUI;
use QUI\ERP\Accounting\Payments\Gateway\Gateway; use QUI\ERP\Accounting\Payments\Gateway\Gateway;
use QUI\ERP\Accounting\Payments\Transactions\Factory as TransactionFactory;
use QUI\ERP\Accounting\Payments\Transactions\Transaction; use QUI\ERP\Accounting\Payments\Transactions\Transaction;
use QUI\ERP\Order\AbstractOrder; use QUI\ERP\Order\AbstractOrder;
use QUI\ERP\Order\Handler as OrderHandler; use QUI\ERP\Order\Handler as OrderHandler;
use QUI\ERP\Accounting\Payments\Transactions\Factory as TransactionFactory;
use Stripe\Exception\ApiErrorException; use Stripe\Exception\ApiErrorException;
use Stripe\PaymentIntent as StripePaymentIntent; use Stripe\PaymentIntent as StripePaymentIntent;
use Stripe\Refund as StripeRefund; use Stripe\Refund as StripeRefund;
...@@ -24,11 +24,11 @@ abstract class AbstractBasePayment extends QUI\ERP\Accounting\Payments\Api\Abstr ...@@ -24,11 +24,11 @@ abstract class AbstractBasePayment extends QUI\ERP\Accounting\Payments\Api\Abstr
*/ */
const ATTR_STRIPE_PAYMENT_INTENT_ID = 'stripe-PaymentIntentId'; const ATTR_STRIPE_PAYMENT_INTENT_ID = 'stripe-PaymentIntentId';
const ATTR_STRIPE_PAYMENT_METHOD_ID = 'stripe-PaymentMethodId'; const ATTR_STRIPE_PAYMENT_METHOD_ID = 'stripe-PaymentMethodId';
const ATTR_STRIPE_REFUND_ID = 'stripe-RefundId'; const ATTR_STRIPE_REFUND_ID = 'stripe-RefundId';
const ATTR_STRIPE_ORDER_SUCCESSFUL = 'stripe-OrderSuccessful'; const ATTR_STRIPE_ORDER_SUCCESSFUL = 'stripe-OrderSuccessful';
const ATTR_STRIPE_BILLING_PLAN_ID = 'stripe-BillingPlanId'; const ATTR_STRIPE_BILLING_PLAN_ID = 'stripe-BillingPlanId';
const ATTR_STRIPE_SUBSCRIPTION_ID = 'stripe-SubscriptionId'; const ATTR_STRIPE_SUBSCRIPTION_ID = 'stripe-SubscriptionId';
const ATTR_STRIPE_INVOICE_ID = 'stripe-InvoiceId'; const ATTR_STRIPE_INVOICE_ID = 'stripe-InvoiceId';
/** /**
* Stripe User attributes * Stripe User attributes
...@@ -38,9 +38,9 @@ abstract class AbstractBasePayment extends QUI\ERP\Accounting\Payments\Api\Abstr ...@@ -38,9 +38,9 @@ abstract class AbstractBasePayment extends QUI\ERP\Accounting\Payments\Api\Abstr
/** /**
* Error codes * Error codes
*/ */
const ERROR_GENERAL = 'error_general'; const ERROR_GENERAL = 'error_general';
const ERROR_REFUND = 'error_refund'; const ERROR_REFUND = 'error_refund';
const ERROR_REFUND_STATUS = 'error_refund_status'; const ERROR_REFUND_STATUS = 'error_refund_status';
const ERROR_REFUND_MISSING_PAYMENT_INTENT_ID = 'error_missing_payment_intent_id'; const ERROR_REFUND_MISSING_PAYMENT_INTENT_ID = 'error_missing_payment_intent_id';
/** /**
...@@ -179,7 +179,7 @@ public function getGatewayDisplay(AbstractOrder $Order, $Step = null) ...@@ -179,7 +179,7 @@ public function getGatewayDisplay(AbstractOrder $Order, $Step = null)
$Control = new PaymentDisplay([ $Control = new PaymentDisplay([
'paymentMethod' => $type, 'paymentMethod' => $type,
'infoText' => $this->getPaymentStepInfo() 'infoText' => $this->getPaymentStepInfo()
]); ]);
$Control->setAttribute('Order', $Order); $Control->setAttribute('Order', $Order);
...@@ -193,7 +193,7 @@ public function getGatewayDisplay(AbstractOrder $Order, $Step = null) ...@@ -193,7 +193,7 @@ public function getGatewayDisplay(AbstractOrder $Order, $Step = null)
'stepTitle' => $stepTitle 'stepTitle' => $stepTitle
]); ]);
$Step->setContent($Engine->fetch(dirname(__FILE__).'/PaymentDisplay.Header.html')); $Step->setContent($Engine->fetch(dirname(__FILE__) . '/PaymentDisplay.Header.html'));
return $Control->create(); return $Control->create();
} }
...@@ -226,7 +226,7 @@ public function createPaymentIntent(AbstractOrder $Order, $paymentMethodId) ...@@ -226,7 +226,7 @@ public function createPaymentIntent(AbstractOrder $Order, $paymentMethodId)
$PaymentIntent = $this->createPaymentIntentForOrder($Order, $paymentMethodId); $PaymentIntent = $this->createPaymentIntentForOrder($Order, $paymentMethodId);
$Order->setPaymentData(self::ATTR_STRIPE_PAYMENT_INTENT_ID, $PaymentIntent->id); $Order->setPaymentData(self::ATTR_STRIPE_PAYMENT_INTENT_ID, $PaymentIntent->id);
$this->addOrderHistoryEntry($Order, 'PaymentIntent '.$PaymentIntent->id.' created.'); $this->addOrderHistoryEntry($Order, 'PaymentIntent ' . $PaymentIntent->id . ' created.');
return $PaymentIntent; return $PaymentIntent;
} }
...@@ -268,9 +268,11 @@ public function confirmPaymentIntent(AbstractOrder $Order, StripePaymentIntent $ ...@@ -268,9 +268,11 @@ public function confirmPaymentIntent(AbstractOrder $Order, StripePaymentIntent $
$confirmData = []; $confirmData = [];
if ($PaymentIntent->status === $PaymentIntent::STATUS_REQUIRES_ACTION if (
&& $PaymentIntent->next_action->type === 'use_stripe_sdk') { $PaymentIntent->status === $PaymentIntent::STATUS_REQUIRES_ACTION
$confirmData['status'] = 'action_required'; && $PaymentIntent->next_action->type === 'use_stripe_sdk'
) {
$confirmData['status'] = 'action_required';
$confirmData['clientSecret'] = $PaymentIntent->client_secret; $confirmData['clientSecret'] = $PaymentIntent->client_secret;
$this->addOrderHistoryEntry($Order, 'Additional user action required for PaymentIntent confirmation.'); $this->addOrderHistoryEntry($Order, 'Additional user action required for PaymentIntent confirmation.');
...@@ -303,7 +305,7 @@ public function confirmPaymentIntent(AbstractOrder $Order, StripePaymentIntent $ ...@@ -303,7 +305,7 @@ public function confirmPaymentIntent(AbstractOrder $Order, StripePaymentIntent $
$this->addOrderHistoryEntry( $this->addOrderHistoryEntry(
$Order, $Order,
'Error while trying to set order as successful: '.$Exception->getMessage() 'Error while trying to set order as successful: ' . $Exception->getMessage()
); );
} }
} else { } else {
...@@ -355,10 +357,12 @@ public function getPaymentIntentByOrder(AbstractOrder $Order) ...@@ -355,10 +357,12 @@ public function getPaymentIntentByOrder(AbstractOrder $Order)
public function refundPayment(Transaction $Transaction, $refundHash, $amount, $reason = '') public function refundPayment(Transaction $Transaction, $refundHash, $amount, $reason = '')
{ {
$Process = new QUI\ERP\Process($Transaction->getGlobalProcessId()); $Process = new QUI\ERP\Process($Transaction->getGlobalProcessId());
$Process->addHistory('Stripe :: Start refund for transaction #'.$Transaction->getTxId()); $Process->addHistory('Stripe :: Start refund for transaction #' . $Transaction->getTxId());
if (!$Transaction->getData(self::ATTR_STRIPE_PAYMENT_INTENT_ID)) { if (!$Transaction->getData(self::ATTR_STRIPE_PAYMENT_INTENT_ID)) {
$Process->addHistory('PayPal :: Transaction cannot be refunded because it is not yet captured / completed.'); $Process->addHistory(
'PayPal :: Transaction cannot be refunded because it is not yet captured / completed.'
);
$this->throwStripeException( $this->throwStripeException(
self::ERROR_REFUND_MISSING_PAYMENT_INTENT_ID, self::ERROR_REFUND_MISSING_PAYMENT_INTENT_ID,
...@@ -371,7 +375,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -371,7 +375,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
} }
$paymentIntentId = $Transaction->getData(self::ATTR_STRIPE_PAYMENT_INTENT_ID); $paymentIntentId = $Transaction->getData(self::ATTR_STRIPE_PAYMENT_INTENT_ID);
$Currency = $Transaction->getCurrency(); $Currency = $Transaction->getCurrency();
// Create a refund transaction (QUIQQER) // Create a refund transaction (QUIQQER)
$RefundTransaction = TransactionFactory::createPaymentRefundTransaction( $RefundTransaction = TransactionFactory::createPaymentRefundTransaction(
...@@ -381,7 +385,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -381,7 +385,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
$Transaction->getPayment()->getName(), $Transaction->getPayment()->getName(),
[ [
'isRefund' => 1, 'isRefund' => 1,
'message' => $reason 'message' => $reason
], ],
null, null,
false, false,
...@@ -393,12 +397,12 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -393,12 +397,12 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
// Create refund (Stripe) // Create refund (Stripe)
try { try {
$PaymentIntent = StripePaymentIntent::retrieve($paymentIntentId); $PaymentIntent = StripePaymentIntent::retrieve($paymentIntentId);
$AmountValue = new QUI\ERP\Accounting\CalculationValue($amount, $Transaction->getCurrency(), 2); $AmountValue = new QUI\ERP\Accounting\CalculationValue($amount, $Transaction->getCurrency(), 2);
$refundAmount = $AmountValue->get() * 100; // convert to smallest currency unit $refundAmount = $AmountValue->get() * 100; // convert to smallest currency unit
$Refund = StripeRefund::create([ $Refund = StripeRefund::create([
'charge' => $PaymentIntent->charges->data[0]->id, 'charge' => $PaymentIntent->charges->data[0]->id,
'amount' => $refundAmount, 'amount' => $refundAmount,
// 'reason' => StripeRefund::REASON_REQUESTED_BY_CUSTOMER, // 'reason' => StripeRefund::REASON_REQUESTED_BY_CUSTOMER,
'metadata' => [ 'metadata' => [
'refundTxId' => $RefundTransaction->getTxId() 'refundTxId' => $RefundTransaction->getTxId()
...@@ -414,9 +418,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -414,9 +418,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
'quiqqer/payment-stripe', 'quiqqer/payment-stripe',
'history.refund.error_api', 'history.refund.error_api',
[ [
'amount' => $amount, 'amount' => $amount,
'currency' => $Currency->getCode(), 'currency' => $Currency->getCode(),
'txId' => $Transaction->getTxId() 'txId' => $Transaction->getTxId()
] ]
) )
); );
...@@ -436,9 +440,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -436,9 +440,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
'history.refund.success', 'history.refund.success',
[ [
'refundId' => $Refund->id, 'refundId' => $Refund->id,
'amount' => $amount, 'amount' => $amount,
'currency' => $Currency->getCode(), 'currency' => $Currency->getCode(),
'txId' => $Transaction->getTxId() 'txId' => $Transaction->getTxId()
] ]
) )
); );
...@@ -460,9 +464,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -460,9 +464,9 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
'history.refund.pending', 'history.refund.pending',
[ [
'refundId' => $Refund->id, 'refundId' => $Refund->id,
'amount' => $amount, 'amount' => $amount,
'currency' => $Currency->getCode(), 'currency' => $Currency->getCode(),
'txId' => $Transaction->getTxId() 'txId' => $Transaction->getTxId()
] ]
) )
); );
...@@ -483,12 +487,12 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -483,12 +487,12 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
'quiqqer/payment-stripe', 'quiqqer/payment-stripe',
'history.refund.error_status', 'history.refund.error_status',
[ [
'refundId' => $Refund->id, 'refundId' => $Refund->id,
'refundStatus' => $Refund->status, 'refundStatus' => $Refund->status,
'failureReason' => $stripeFailureReason, 'failureReason' => $stripeFailureReason,
'amount' => $amount, 'amount' => $amount,
'currency' => $Currency->getCode(), 'currency' => $Currency->getCode(),
'txId' => $Transaction->getTxId() 'txId' => $Transaction->getTxId()
] ]
) )
); );
...@@ -506,7 +510,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r ...@@ -506,7 +510,7 @@ public function refundPayment(Transaction $Transaction, $refundHash, $amount, $r
*/ */
protected function addOrderHistoryEntry(AbstractOrder $Order, $msg) protected function addOrderHistoryEntry(AbstractOrder $Order, $msg)
{ {
$Order->addHistory('Stripe :: '.$msg); $Order->addHistory('Stripe :: ' . $msg);
$this->saveOrder($Order); $this->saveOrder($Order);
} }
...@@ -521,9 +525,9 @@ protected function addOrderHistoryEntry(AbstractOrder $Order, $msg) ...@@ -521,9 +525,9 @@ protected function addOrderHistoryEntry(AbstractOrder $Order, $msg)
*/ */
protected function throwStripeException($errorCode = self::ERROR_GENERAL, $exceptionAttributes = []) protected function throwStripeException($errorCode = self::ERROR_GENERAL, $exceptionAttributes = [])
{ {
$L = $this->getLocale(); $L = $this->getLocale();
$lg = 'quiqqer/payment-stripe'; $lg = 'quiqqer/payment-stripe';
$msg = $L->get($lg, 'exception.BasePayment.'.$errorCode); $msg = $L->get($lg, 'exception.BasePayment.' . $errorCode);
$Exception = new StripeException($msg); $Exception = new StripeException($msg);
$Exception->setAttributes($exceptionAttributes); $Exception->setAttributes($exceptionAttributes);
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren