Skip to content
Code-Schnipsel Gruppen Projekte
Commit 24f12d72 erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

Merge branch 'dev' into 'next'

feat: compatiblity to payments v2

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