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'] === '
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';
$paypal = new PayPalExpress();
if (isset($_GET['return']) && $_GET['return'] === '1') {
if (isset($_GET['return']) && $_GET['return'] === '1') {
$session = Session::getInstance();
$conf = Shop::getConfig([CONF_KUNDEN]);
$response = $paypal->GetExpressCheckoutDetails($_SESSION['reshash']['Token']);
unset($_SESSION['Versandart'], $_SESSION['AktiveVersandart']);
$_SESSION['reshash']['Token'] = $response->Token;
$_SESSION['reshash']['Payer'] = $response->PayerInfo->Payer;
$_SESSION['reshash']['PayerID'] = $response->PayerInfo->PayerID;
......
......@@ -8,6 +8,7 @@ error_reporting(0);
ini_set('display_errors', 0);
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\Payment;
......@@ -136,8 +137,19 @@ switch ($action) {
$payment = Payment::get($_GET['id'], $apiContext);
$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')
->setPath('(/potential_payer_info/billing_address')
->setPath('/potential_payer_info/billing_address')
->setValue($billingAddress);
$patchRequest->addPatch($patchBilling);
......@@ -201,32 +213,33 @@ switch ($action) {
$success = isset($_GET['r']) && $_GET['r'] === 'true';
if (!$success) {
$this->doLog("PayPal redirect (user Canceled)", LOGLEVEL_NOTICE);
$api->doLog("PayPal redirect (user canceled)", LOGLEVEL_NOTICE);
_redirect('bestellvorgang.php?editZahlungsart=1');
}
$args = [
'paymentId' => $_GET['paymentId'],
'token' => $_GET['token'],
'payerId' => $_GET['PayerID']
];
$args = [
'paymentId' => $_GET['paymentId'],
'token' => $_GET['token'],
'payerId' => $_GET['PayerID']
];
$validArgs = array_filter($args);
$validArgs = array_filter($args);
if (count($args) !== count($validArgs)) {
$argStr = $this->formatObject((object)$args);
$this->doLog("PayPal redirect (missing arguments)\n{$argStr}", LOGLEVEL_ERROR);
if (count($args) !== count($validArgs)) {
$api->logResult("PayPal redirect (missing arguments)", (object)$args);
_redirect('bestellvorgang.php?editZahlungsart=1');
}
_redirect('bestellvorgang.php?editZahlungsart=1');
}
foreach ($validArgs as $k => $v) {
$api->addCache($k, $v);
}
foreach ($validArgs as $k => $v) {
$api->addCache($k, $v);
}
try {
$payment = Payment::get($validArgs['paymentId'], $apiContext);
$api->addCache('payment', $payment->toJson());
$api->createPaymentSession();
_redirect('bestellvorgang.php');
......@@ -252,7 +265,7 @@ switch ($action) {
$paymentId = $resource->parent_payment;
$order = Shop::DB()->select('tbestellung', 'cSession', $paymentId);
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(
'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
* @param $szPaymentDesc string to shorten
* @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)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
......
......@@ -326,6 +326,7 @@ class PayPalExpress extends PaymentMethod
public function preparePaymentProcess($order)
{
$basket = PayPalHelper::getBasket();
$helper = new WarenkorbHelper();
$doExpressCheckoutPaymentReq = new PayPalAPI\DoExpressCheckoutPaymentReq();
$doExpressCheckoutPaymentRequestDetails = new \PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
......@@ -346,6 +347,19 @@ class PayPalExpress extends PaymentMethod
$paymentDetails->Custom = $order->kBestellung;
$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];
$doExpressCheckoutPaymentRequest = new PayPalAPI\DoExpressCheckoutPaymentRequestType($doExpressCheckoutPaymentRequestDetails);
$doExpressCheckoutPaymentReq->DoExpressCheckoutPaymentRequest = $doExpressCheckoutPaymentRequest;
......@@ -364,37 +378,37 @@ class PayPalExpress extends PaymentMethod
$r = $e->getMessage();
$this->doLog("Response: DoExpressCheckoutPayment:\n\n<pre>{$r}</pre>", LOGLEVEL_NOTICE);
}
switch ($response->Ack) {
case 'Success': {
$paymentInfo = $response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0];
$this->doLog("Payment status: {$paymentInfo->PaymentStatus} (Order: {$order->kBestellung}, Reason: {$paymentInfo->PendingReason})", LOGLEVEL_NOTICE);
if (strcasecmp($paymentInfo->PaymentStatus, 'Completed') === 0) {
$this->addIncomingPayment($order, [
'fBetrag' => $basket->total[WarenkorbHelper::GROSS],
'fZahlungsgebuehr' => $basket->surcharge[WarenkorbHelper::GROSS],
'cISO' => $basket->currency->cISO,
'cZahler' => $_SESSION['reshash']['Payer'],
'cHinweis' => $paymentInfo->TransactionID,
]);
$this->setOrderStatusToPaid($order);
}
break;
}
// https://developer.paypal.com/docs/classic/express-checkout/ht_ec_fundingfailure10486/
case 'Failure': {
$error = $response->Errors[0];
if ((int)$error->ErrorCode === 10486) {
$redirect = $this->PayPalURL . $_SESSION['reshash']['Token'];
header("Location: {$redirect}");
exit;
}
break;
}
}
switch ($response->Ack) {
case 'Success': {
$paymentInfo = $response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0];
$this->doLog("Payment status: {$paymentInfo->PaymentStatus} (Order: {$order->kBestellung}, Reason: {$paymentInfo->PendingReason})", LOGLEVEL_NOTICE);
if (strcasecmp($paymentInfo->PaymentStatus, 'Completed') === 0) {
$this->addIncomingPayment($order, [
'fBetrag' => $basket->total[WarenkorbHelper::GROSS],
'fZahlungsgebuehr' => $basket->surcharge[WarenkorbHelper::GROSS],
'cISO' => $basket->currency->cISO,
'cZahler' => $_SESSION['reshash']['Payer'],
'cHinweis' => $paymentInfo->TransactionID,
]);
$this->setOrderStatusToPaid($order);
}
break;
}
// https://developer.paypal.com/docs/classic/express-checkout/ht_ec_fundingfailure10486/
case 'Failure': {
$error = $response->Errors[0];
if ((int)$error->ErrorCode === 10486) {
$redirect = $this->PayPalURL . $_SESSION['reshash']['Token'];
header("Location: {$redirect}");
exit;
}
break;
}
}
Session::getInstance()->cleanUp();
......
......@@ -540,27 +540,28 @@ class PayPalPlus extends PaymentMethod
public function preparePaymentProcess($order)
{
try {
$lastOrderId = $this->getCache('lastOrderId');
$orderNumber = (int)$this->getCache('orderNumber');
$paymentId = $this->getCache('paymentId');
$paymentData = $this->getCache('payment');
$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)) {
// 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());
throw new Exception(sprintf('Missing payment/payer id, %s (%s)', $str, $this->moduleID));
}
......@@ -569,38 +570,37 @@ class PayPalPlus extends PaymentMethod
$basket = PayPalHelper::getBasket($helper);
$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()));
}
$orderNumber = baueBestellnummer();
$this->patch($payment, $orderNumber);
// Create payment request
if ($payment->getState() == 'created') {
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$execution = new PaymentExecution();
$execution->setPayerId($payerId);
$details = new Details();
$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();
$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);
$amount = new Amount();
$amount->setCurrency($basket->currency->cISO)
->setTotal($basket->total[WarenkorbHelper::GROSS])
->setDetails($details);
$amount = new Amount();
$amount->setCurrency($basket->currency->cISO)
->setTotal($basket->total[WarenkorbHelper::GROSS])
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction = new Transaction();
$transaction->setAmount($amount);
//->setInvoiceNumber($orderNumber) // #437
$execution->addTransaction($transaction);
$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->cSession = $paymentId;
......@@ -648,16 +648,15 @@ class PayPalPlus extends PaymentMethod
$order->updateInDB();
if ($payment->getState() === 'approved')
{
try {
$state = $payment->getTransactions()[0]
->getRelatedResources()[0]
->getSale()
->getState();
} catch (Exception $ex) {
$state = 'invalid';
}
if ($payment->getState() === 'approved') {
try {
$state = $payment->getTransactions()[0]
->getRelatedResources()[0]
->getSale()
->getState();
} catch (Exception $ex) {
$state = 'invalid';
}
if ($state === 'completed') {
$ip = new stdClass();
......@@ -682,7 +681,7 @@ class PayPalPlus extends PaymentMethod
}
$this->unsetCache();
$this->addCache('lastOrderId', $order->kBestellung);
$this->addCache('lastOrderId', $order->kBestellung);
$this->redirectToOrderDetails($order);
......@@ -711,14 +710,14 @@ class PayPalPlus extends PaymentMethod
*
* @return bool
*/
public function redirectToOrderDetails($order)
{
$paymentHash = $this->generateHash($order);
$returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash;
header("location: {$returnUrl}");
exit;
}
public function redirectToOrderDetails($order)
{
$paymentHash = $this->generateHash($order);
$returnUrl = Shop::getURL().'/bestellabschluss.php?i='.$paymentHash;
header("location: {$returnUrl}");
exit;
}
/**
* @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