Commit afe7608d authored by Andy J's avatar Andy J

p2

parent 9c139a1f
...@@ -189,4 +189,9 @@ if ($oPlugin->oPluginEinstellungAssoc_arr['jtl_paypal_express_cart_popup'] === ' ...@@ -189,4 +189,9 @@ if ($oPlugin->oPluginEinstellungAssoc_arr['jtl_paypal_express_cart_popup'] === '
pq('body')->append($tpl); pq('body')->append($tpl);
} }
} }
}
if ($pageType === PAGE_BESTELLVORGANG && $GLOBALS['step'] === 'Bestaetigung') {
$tpl = $smarty->fetch($oPlugin->cFrontendPfad . 'template/inc_order_confirmation.tpl');
pq('body')->append($tpl);
} }
\ No newline at end of file
...@@ -19,11 +19,13 @@ require_once PFAD_INCLUDES . 'registrieren_inc.php'; ...@@ -19,11 +19,13 @@ require_once PFAD_INCLUDES . 'registrieren_inc.php';
$paypal = new PayPalExpress(); $paypal = new PayPalExpress();
if (isset($_GET['return']) && $_GET['return'] === '1') { if (isset($_GET['return']) && $_GET['return'] === '1') {
$session = Session::getInstance(); $session = Session::getInstance();
$conf = Shop::getConfig([CONF_KUNDEN]); $conf = Shop::getConfig([CONF_KUNDEN]);
$response = $paypal->GetExpressCheckoutDetails($_SESSION['reshash']['Token']); $response = $paypal->GetExpressCheckoutDetails($_SESSION['reshash']['Token']);
unset($_SESSION['Versandart'], $_SESSION['AktiveVersandart']);
$_SESSION['reshash']['Token'] = $response->Token; $_SESSION['reshash']['Token'] = $response->Token;
$_SESSION['reshash']['Payer'] = $response->PayerInfo->Payer; $_SESSION['reshash']['Payer'] = $response->PayerInfo->Payer;
$_SESSION['reshash']['PayerID'] = $response->PayerInfo->PayerID; $_SESSION['reshash']['PayerID'] = $response->PayerInfo->PayerID;
......
...@@ -8,6 +8,7 @@ error_reporting(0); ...@@ -8,6 +8,7 @@ error_reporting(0);
ini_set('display_errors', 0); ini_set('display_errors', 0);
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php'; require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php';
require_once PFAD_ROOT.PFAD_INCLUDES.'bestellabschluss_inc.php';
use PayPal\Api\Error; use PayPal\Api\Error;
use PayPal\Api\Payment; use PayPal\Api\Payment;
...@@ -136,8 +137,19 @@ switch ($action) { ...@@ -136,8 +137,19 @@ switch ($action) {
$payment = Payment::get($_GET['id'], $apiContext); $payment = Payment::get($_GET['id'], $apiContext);
$patchRequest = new \PayPal\Api\PatchRequest(); $patchRequest = new \PayPal\Api\PatchRequest();
$orderNumber = baueBestellnummer();
$api->addCache('orderNumber', $orderNumber);
/*
$patchOrderNumber = new \PayPal\Api\Patch();
$patchOrderNumber->setOp('add')
->setPath('(/transactions/0/invoice_number')
->setValue($orderNumber);
$patchRequest->addPatch($patchOrderNumber);
*/
$patchBilling = new \PayPal\Api\Patch();
$patchBilling->setOp('add') $patchBilling->setOp('add')
->setPath('(/potential_payer_info/billing_address') ->setPath('/potential_payer_info/billing_address')
->setValue($billingAddress); ->setValue($billingAddress);
$patchRequest->addPatch($patchBilling); $patchRequest->addPatch($patchBilling);
...@@ -201,32 +213,33 @@ switch ($action) { ...@@ -201,32 +213,33 @@ switch ($action) {
$success = isset($_GET['r']) && $_GET['r'] === 'true'; $success = isset($_GET['r']) && $_GET['r'] === 'true';
if (!$success) { if (!$success) {
$this->doLog("PayPal redirect (user Canceled)", LOGLEVEL_NOTICE); $api->doLog("PayPal redirect (user canceled)", LOGLEVEL_NOTICE);
_redirect('bestellvorgang.php?editZahlungsart=1'); _redirect('bestellvorgang.php?editZahlungsart=1');
} }
$args = [ $args = [
'paymentId' => $_GET['paymentId'], 'paymentId' => $_GET['paymentId'],
'token' => $_GET['token'], 'token' => $_GET['token'],
'payerId' => $_GET['PayerID'] 'payerId' => $_GET['PayerID']
]; ];
$validArgs = array_filter($args); $validArgs = array_filter($args);
if (count($args) !== count($validArgs)) { if (count($args) !== count($validArgs)) {
$argStr = $this->formatObject((object)$args); $api->logResult("PayPal redirect (missing arguments)", (object)$args);
$this->doLog("PayPal redirect (missing arguments)\n{$argStr}", LOGLEVEL_ERROR);
_redirect('bestellvorgang.php?editZahlungsart=1'); _redirect('bestellvorgang.php?editZahlungsart=1');
} }
foreach ($validArgs as $k => $v) { foreach ($validArgs as $k => $v) {
$api->addCache($k, $v); $api->addCache($k, $v);
} }
try { try {
$payment = Payment::get($validArgs['paymentId'], $apiContext); $payment = Payment::get($validArgs['paymentId'], $apiContext);
$api->addCache('payment', $payment->toJson());
$api->createPaymentSession(); $api->createPaymentSession();
_redirect('bestellvorgang.php'); _redirect('bestellvorgang.php');
...@@ -252,7 +265,7 @@ switch ($action) { ...@@ -252,7 +265,7 @@ switch ($action) {
$paymentId = $resource->parent_payment; $paymentId = $resource->parent_payment;
$order = Shop::DB()->select('tbestellung', 'cSession', $paymentId); $order = Shop::DB()->select('tbestellung', 'cSession', $paymentId);
if (is_object($order) && intval($order->kBestellung) > 0) { if (is_object($order) && intval($order->kBestellung) > 0) {
$api->doLog("Incoming payment for order (id: {$order->kBestellung} / paypal id: {$resource->id}) already received (skipped)", LOGLEVEL_NOTICE); $api->doLog("Incoming payment for order (id: {$order->kBestellung} / paypal id: {$resource->id}) already received (skipped)", LOGLEVEL_NOTICE);
$incomingPayment = Shop::DB()->select( $incomingPayment = Shop::DB()->select(
'tzahlungseingang', 'tzahlungseingang',
......
<div class="modal modal-center fade" id="ppp-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<h2 id="pp-loading-body"><i class="fa fa-spinner fa-spin fa-fw"></i> Ihre Bestellung wird abgeschlossen</h2>
</div>
</div>
</div>
</div>
<script>
$(function() {
var submitted = false;
// $(window).bind('unload', function (e) { console.log('unload'); return false; });
//$(window).bind('beforeunload', function (e) { console.log('beforeunload', submitted); return submitted; });
$('#complete_order').on('submit', function() {
submitted = true;
$(this).find('input[type="submit"]')
.addClass('disabled')
.attr('disabled', true);
$('#ppp-modal').modal({
backdrop: 'static'
});
$('#ppp-modal').modal('show');
return true;
});
});
</script>
\ No newline at end of file
...@@ -733,7 +733,7 @@ class PayPalHelper ...@@ -733,7 +733,7 @@ class PayPalHelper
* @param $szPaymentDesc string to shorten * @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit' * @return string string of length 'nLimit'
*/ */
function shortenPaymentName($szPaymentDesc) { public static function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered) $nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good) $nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...'; $szPlaceHolder = '...';
......
...@@ -326,6 +326,7 @@ class PayPalExpress extends PaymentMethod ...@@ -326,6 +326,7 @@ class PayPalExpress extends PaymentMethod
public function preparePaymentProcess($order) public function preparePaymentProcess($order)
{ {
$basket = PayPalHelper::getBasket(); $basket = PayPalHelper::getBasket();
$helper = new WarenkorbHelper();
$doExpressCheckoutPaymentReq = new PayPalAPI\DoExpressCheckoutPaymentReq(); $doExpressCheckoutPaymentReq = new PayPalAPI\DoExpressCheckoutPaymentReq();
$doExpressCheckoutPaymentRequestDetails = new \PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType(); $doExpressCheckoutPaymentRequestDetails = new \PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
...@@ -346,6 +347,19 @@ class PayPalExpress extends PaymentMethod ...@@ -346,6 +347,19 @@ class PayPalExpress extends PaymentMethod
$paymentDetails->Custom = $order->kBestellung; $paymentDetails->Custom = $order->kBestellung;
$paymentDetails->NotifyURL = $this->oPlugin->cFrontendPfadURLSSL . 'notify.php?type=express'; $paymentDetails->NotifyURL = $this->oPlugin->cFrontendPfadURLSSL . 'notify.php?type=express';
$sAddress = $helper->getShippingAddress();
$shippingAddress = new \PayPal\EBLBaseComponents\AddressType();
$shippingAddress->Name = "{$sAddress->cVorname} {$sAddress->cNachname}";
$shippingAddress->Street1 = "{$sAddress->cStrasse} {$sAddress->cHausnummer}";
$shippingAddress->Street2 = @$sAddress->cAdressZusatz;
$shippingAddress->CityName = $sAddress->cOrt;
$shippingAddress->StateOrProvince = PayPalHelper::getState($sAddress);
$shippingAddress->Country = $sAddress->cLand;
$shippingAddress->PostalCode = $sAddress->cPLZ;
$paymentDetails->ShipToAddress = utf8_convert_recursive($shippingAddress);
$doExpressCheckoutPaymentRequestDetails->PaymentDetails = [$paymentDetails]; $doExpressCheckoutPaymentRequestDetails->PaymentDetails = [$paymentDetails];
$doExpressCheckoutPaymentRequest = new PayPalAPI\DoExpressCheckoutPaymentRequestType($doExpressCheckoutPaymentRequestDetails); $doExpressCheckoutPaymentRequest = new PayPalAPI\DoExpressCheckoutPaymentRequestType($doExpressCheckoutPaymentRequestDetails);
$doExpressCheckoutPaymentReq->DoExpressCheckoutPaymentRequest = $doExpressCheckoutPaymentRequest; $doExpressCheckoutPaymentReq->DoExpressCheckoutPaymentRequest = $doExpressCheckoutPaymentRequest;
...@@ -364,37 +378,37 @@ class PayPalExpress extends PaymentMethod ...@@ -364,37 +378,37 @@ class PayPalExpress extends PaymentMethod
$r = $e->getMessage(); $r = $e->getMessage();
$this->doLog("Response: DoExpressCheckoutPayment:\n\n<pre>{$r}</pre>", LOGLEVEL_NOTICE); $this->doLog("Response: DoExpressCheckoutPayment:\n\n<pre>{$r}</pre>", LOGLEVEL_NOTICE);
} }
switch ($response->Ack) { switch ($response->Ack) {
case 'Success': { case 'Success': {
$paymentInfo = $response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]; $paymentInfo = $response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0];
$this->doLog("Payment status: {$paymentInfo->PaymentStatus} (Order: {$order->kBestellung}, Reason: {$paymentInfo->PendingReason})", LOGLEVEL_NOTICE); $this->doLog("Payment status: {$paymentInfo->PaymentStatus} (Order: {$order->kBestellung}, Reason: {$paymentInfo->PendingReason})", LOGLEVEL_NOTICE);
if (strcasecmp($paymentInfo->PaymentStatus, 'Completed') === 0) { if (strcasecmp($paymentInfo->PaymentStatus, 'Completed') === 0) {
$this->addIncomingPayment($order, [ $this->addIncomingPayment($order, [
'fBetrag' => $basket->total[WarenkorbHelper::GROSS], 'fBetrag' => $basket->total[WarenkorbHelper::GROSS],
'fZahlungsgebuehr' => $basket->surcharge[WarenkorbHelper::GROSS], 'fZahlungsgebuehr' => $basket->surcharge[WarenkorbHelper::GROSS],
'cISO' => $basket->currency->cISO, 'cISO' => $basket->currency->cISO,
'cZahler' => $_SESSION['reshash']['Payer'], 'cZahler' => $_SESSION['reshash']['Payer'],
'cHinweis' => $paymentInfo->TransactionID, 'cHinweis' => $paymentInfo->TransactionID,
]); ]);
$this->setOrderStatusToPaid($order); $this->setOrderStatusToPaid($order);
} }
break; break;
} }
// https://developer.paypal.com/docs/classic/express-checkout/ht_ec_fundingfailure10486/ // https://developer.paypal.com/docs/classic/express-checkout/ht_ec_fundingfailure10486/
case 'Failure': { case 'Failure': {
$error = $response->Errors[0]; $error = $response->Errors[0];
if ((int)$error->ErrorCode === 10486) { if ((int)$error->ErrorCode === 10486) {
$redirect = $this->PayPalURL . $_SESSION['reshash']['Token']; $redirect = $this->PayPalURL . $_SESSION['reshash']['Token'];
header("Location: {$redirect}"); header("Location: {$redirect}");
exit; exit;
} }
break; break;
} }
} }
Session::getInstance()->cleanUp(); Session::getInstance()->cleanUp();
......
...@@ -540,27 +540,28 @@ class PayPalPlus extends PaymentMethod ...@@ -540,27 +540,28 @@ class PayPalPlus extends PaymentMethod
public function preparePaymentProcess($order) public function preparePaymentProcess($order)
{ {
try { try {
$lastOrderId = $this->getCache('lastOrderId'); $orderNumber = (int)$this->getCache('orderNumber');
$paymentId = $this->getCache('paymentId'); $paymentId = $this->getCache('paymentId');
$paymentData = $this->getCache('payment');
$payerId = $this->getCache('payerId'); $payerId = $this->getCache('payerId');
$payment = new Payment($paymentData);
// order exists in database?
if (intval($lastOrderId) > 0) {
$lastOrder = new Bestellung($lastOrderId);
$lastOrder->fuelleBestellung(false);
if ($lastOrder->kBestellung > 0) {
$paymentHash = $this->generateHash($order);
$returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash;
header("location: {$returnUrl}");
}
}
// payment related information already deleted (multiply order submission)
if (empty($paymentId) || empty($payerId)) { if (empty($paymentId) || empty($payerId)) {
// payment related information already deleted (multiply order submission)
// order already saved?
$lastOrder = new Bestellung($lastOrderId);
$lastOrder->fuelleBestellung(false);
if ($lastOrder->kBestellung > 0) {
$paymentHash = $this->generateHash($order);
$returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash;
header("location: {$returnUrl}");
}
$str = json_encode($this->getCache()); $str = json_encode($this->getCache());
throw new Exception(sprintf('Missing payment/payer id, %s (%s)', $str, $this->moduleID)); throw new Exception(sprintf('Missing payment/payer id, %s (%s)', $str, $this->moduleID));
} }
...@@ -569,38 +570,37 @@ class PayPalPlus extends PaymentMethod ...@@ -569,38 +570,37 @@ class PayPalPlus extends PaymentMethod
$basket = PayPalHelper::getBasket($helper); $basket = PayPalHelper::getBasket($helper);
$apiContext = $this->getContext(); $apiContext = $this->getContext();
$payment = Payment::get($paymentId, $apiContext); // $payment = Payment::get($paymentId, $apiContext);
if ($payment->getState() != 'created') { if (!in_array($payment->getState(), ['created', 'approved'])) {
throw new Exception(sprintf('Unhandled payment state "%s"', $payment->getState())); throw new Exception(sprintf('Unhandled payment state "%s"', $payment->getState()));
} }
$orderNumber = baueBestellnummer(); // Create payment request
$this->patch($payment, $orderNumber); if ($payment->getState() == 'created') {
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$execution = new PaymentExecution(); $details = new Details();
$execution->setPayerId($payerId); $details->setShipping($basket->shipping[WarenkorbHelper::GROSS])
->setSubtotal($basket->article[WarenkorbHelper::GROSS])
->setHandlingFee($basket->surcharge[WarenkorbHelper::GROSS])
->setShippingDiscount($basket->discount[WarenkorbHelper::GROSS] * -1)
->setTax(0.00);
$details = new Details(); $amount = new Amount();
$details->setShipping($basket->shipping[WarenkorbHelper::GROSS]) $amount->setCurrency($basket->currency->cISO)
->setSubtotal($basket->article[WarenkorbHelper::GROSS]) ->setTotal($basket->total[WarenkorbHelper::GROSS])
->setHandlingFee($basket->surcharge[WarenkorbHelper::GROSS]) ->setDetails($details);
->setShippingDiscount($basket->discount[WarenkorbHelper::GROSS] * -1)
->setTax(0.00);
$amount = new Amount(); $transaction = new Transaction();
$amount->setCurrency($basket->currency->cISO) $transaction->setAmount($amount);
->setTotal($basket->total[WarenkorbHelper::GROSS])
->setDetails($details);
$transaction = new Transaction(); $execution->addTransaction($transaction);
$transaction->setAmount($amount);
//->setInvoiceNumber($orderNumber) // #437
$execution->addTransaction($transaction); $payment->execute($execution, $apiContext);
$this->logResult('ExecutePayment', $execution, $payment);
$payment->execute($execution, $apiContext); }
$this->logResult('ExecutePayment', $execution, $payment);
$order = finalisiereBestellung($orderNumber, true); $order = finalisiereBestellung($orderNumber, true);
$order->cSession = $paymentId; $order->cSession = $paymentId;
...@@ -648,16 +648,15 @@ class PayPalPlus extends PaymentMethod ...@@ -648,16 +648,15 @@ class PayPalPlus extends PaymentMethod
$order->updateInDB(); $order->updateInDB();
if ($payment->getState() === 'approved') if ($payment->getState() === 'approved') {
{ try {
try { $state = $payment->getTransactions()[0]
$state = $payment->getTransactions()[0] ->getRelatedResources()[0]
->getRelatedResources()[0] ->getSale()
->getSale() ->getState();
->getState(); } catch (Exception $ex) {
} catch (Exception $ex) { $state = 'invalid';
$state = 'invalid'; }
}
if ($state === 'completed') { if ($state === 'completed') {
$ip = new stdClass(); $ip = new stdClass();
...@@ -682,7 +681,7 @@ class PayPalPlus extends PaymentMethod ...@@ -682,7 +681,7 @@ class PayPalPlus extends PaymentMethod
} }
$this->unsetCache(); $this->unsetCache();
$this->addCache('lastOrderId', $order->kBestellung); $this->addCache('lastOrderId', $order->kBestellung);
$this->redirectToOrderDetails($order); $this->redirectToOrderDetails($order);
...@@ -711,14 +710,14 @@ class PayPalPlus extends PaymentMethod ...@@ -711,14 +710,14 @@ class PayPalPlus extends PaymentMethod
* *
* @return bool * @return bool
*/ */
public function redirectToOrderDetails($order) public function redirectToOrderDetails($order)
{ {
$paymentHash = $this->generateHash($order); $paymentHash = $this->generateHash($order);
$returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash; $returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash;
header("location: {$returnUrl}"); header("location: {$returnUrl}");
exit; exit;
} }
/** /**
* @param array $oArtikel_arr * @param array $oArtikel_arr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment