/** * @param ControllerAction $action */ public function onPaypalPlus(ControllerAction $action) { $config = $this->config; $router = $action->Front()->Router(); $view = $action->View(); $user = $view->getAssign('sUserData'); $basket = $view->getAssign('sBasket'); $cancelUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'cancel', 'forceSecure' => true)); $returnUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'return', 'forceSecure' => true)); $profile = $this->getProfile(); $this->restClient->setAuthToken(); $uri = 'payments/payment'; $params = array('intent' => 'sale', 'experience_profile_id' => $profile['id'], 'payer' => array('payment_method' => 'paypal'), 'transactions' => $this->getTransactionData($basket, $user), 'redirect_urls' => array('return_url' => $returnUrl, 'cancel_url' => $cancelUrl)); $payment = $this->restClient->create($uri, $params); if (!empty($payment['links'][1]['href'])) { $view->assign('PaypalPlusApprovalUrl', $payment['links'][1]['href']); $view->assign('PaypalPlusModeSandbox', $config->get('paypalSandbox')); $view->assign('PaypalLocale', $this->paypalBootstrap->getLocaleCode()); $db = $this->bootstrap->get('db'); $sql = 'SELECT paymentmeanID AS id, paypal_plus_media AS media FROM s_core_paymentmeans_attributes WHERE paypal_plus_active = 1'; $paymentMethods = $db->fetchAssoc($sql); $view->assign('PaypalPlusThirdPartyPaymentMethods', $paymentMethods); $this->session->PaypalPlusPayment = $payment['id']; } }
/** * Returns the prepared customer parameter data. * * @return array */ protected function getCustomerParameter() { $user = $this->getUser(); if (empty($user)) { return array('LOCALECODE' => $this->plugin->getLocaleCode(true)); } $shipping = $user['shippingaddress']; $name = $shipping['firstname'] . ' ' . $shipping['lastname']; if (!empty($shipping['company'])) { $name = $shipping['company'] . ' - ' . $name; } if (!empty($shipping['streetnumber'])) { $shipping['street'] .= ' ' . $shipping['streetnumber']; } if (!empty($shipping['additional_address_line1'])) { $shipping['street2'] = $shipping['additional_address_line1']; if (!empty($shipping['additional_address_line2'])) { $shipping['street2'] .= ' ' . $shipping['additional_address_line2']; } } else { $shipping['street2'] = ''; } $customer = array('CUSTOMERSERVICENUMBER' => $user['billingaddress']['customernumber'], 'SHIPTONAME' => $name, 'SHIPTOSTREET' => $shipping['street'], 'SHIPTOSTREET2' => $shipping['street2'], 'SHIPTOZIP' => $shipping['zipcode'], 'SHIPTOCITY' => $shipping['city'], 'SHIPTOCOUNTRY' => $user['additional']['countryShipping']['countryiso'], 'EMAIL' => $user['additional']['user']['email'], 'SHIPTOPHONENUM' => $user['billingaddress']['phone'], 'LOCALECODE' => $this->plugin->getLocaleCode(true)); if (!empty($user['additional']['stateShipping']['shortcode'])) { $customer['SHIPTOSTATE'] = $user['additional']['stateShipping']['shortcode']; } return $customer; }
private function saveInvoiceInstructions($orderNumber, $payment) { /** * SAVE THE INVOICE-INSTRUCTIONS FROM PAYPAL */ /** @var PaymentInstructionProvider $paymentInstructionProvider */ $paymentInstructionProvider = $this->paypalBootstrap->get('payment_instruction_provider'); $paymentInstructionProvider->saveInstructionByOrdernumber($orderNumber, $payment['payment_instruction']); }
/** * @return array */ private function getProfileData() { $template = $this->bootstrap->get('template'); $router = $this->bootstrap->get('router'); $shop = $this->bootstrap->get('shop'); $localeCode = $this->paypalBootstrap->getLocaleCode(true); $profileName = "{$shop->getHost()}{$shop->getBasePath()}[{$shop->getId()}]"; $shopName = $this->config->get('paypalBrandName') ?: $this->bootstrap->get('config')->get('shopName'); // (max length 127) if (strlen($shopName) > 127) { $shopName = substr($shopName, 0, 124) . '...'; } $logoImage = $this->config->get('paypalLogoImage'); $logoImage = 'string:{link file=' . var_export($logoImage, true) . ' fullPath}'; $logoImage = $template->fetch($logoImage); $notifyUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'notify', 'forceSecure' => true)); return array('name' => $profileName, 'presentation' => array('brand_name' => $shopName, 'logo_image' => $logoImage, 'locale_code' => $localeCode), 'input_fields' => array('allow_note' => true, 'no_shipping' => 0, 'address_override' => 1), 'flow_config' => array('bank_txn_pending_url' => $notifyUrl)); }
/** * Do payment action */ public function doActionAction() { $transactionId = $this->Request()->getParam('transactionId'); // Load the correct shop in order to use the correct api credentials $this->registerShopByTransactionId($transactionId); $config = $this->plugin->Config(); $client = $this->get('paypalClient'); $action = $this->Request()->getParam('paymentAction'); $amount = $this->Request()->getParam('paymentAmount'); $amount = str_replace(',', '.', $amount); $currency = $this->Request()->getParam('paymentCurrency'); $orderNumber = $this->Request()->getParam('orderNumber'); $full = $this->Request()->getParam('paymentFull') === 'true'; $last = $this->Request()->getParam('paymentLast') === 'true'; $note = $this->Request()->getParam('note'); $invoiceId = null; if ($config->get('paypalSendInvoiceId') === true) { $prefix = $config->get('paypalPrefixInvoiceId'); if (!empty($prefix)) { // Set prefixed invoice id - Remove special chars and spaces $prefix = str_replace(' ', '', $prefix); $prefix = preg_replace('/[^A-Za-z0-9\\-]/', '', $prefix); $invoiceId = $prefix . $orderNumber; } else { $invoiceId = $orderNumber; } } try { switch ($action) { case 'refund': $data = array('TRANSACTIONID' => $transactionId, 'REFUNDTYPE' => $full ? 'Full' : 'Partial', 'AMT' => $full ? '' : $amount, 'CURRENCYCODE' => $full ? '' : $currency, 'NOTE' => $note); if ($invoiceId) { $data['INVOICEID'] = $invoiceId; } $result = $client->RefundTransaction($data); break; case 'auth': $result = $client->doReAuthorization(array('AUTHORIZATIONID' => $transactionId, 'AMT' => $amount, 'CURRENCYCODE' => $currency)); break; case 'capture': $data = array('AUTHORIZATIONID' => $transactionId, 'AMT' => $amount, 'CURRENCYCODE' => $currency, 'COMPLETETYPE' => $last ? 'Complete' : 'NotComplete', 'NOTE' => $note); if ($invoiceId) { $data['INVOICEID'] = $invoiceId; } $result = $client->doCapture($data); break; case 'void': $result = $client->doVoid(array('AUTHORIZATIONID' => $transactionId, 'NOTE' => $note)); break; case 'book': $result = $client->doAuthorization(array('TRANSACTIONID' => $transactionId, 'AMT' => $amount, 'CURRENCYCODE' => $currency)); if ($result['ACK'] == 'Success') { $data = array('AUTHORIZATIONID' => $result['TRANSACTIONID'], 'AMT' => $amount, 'CURRENCYCODE' => $currency, 'COMPLETETYPE' => $last ? 'Complete' : 'NotComplete', 'NOTE' => $note); if ($invoiceId) { $data['INVOICEID'] = $invoiceId; } $result = $client->doCapture($data); } break; default: return; } if ($result['ACK'] != 'Success') { throw new Exception('[' . $result['L_SEVERITYCODE0'] . '] ' . $result['L_SHORTMESSAGE0'] . " " . $result['L_LONGMESSAGE0'] . "<br>\n"); } // Switch transaction id if ($action !== 'book' && $action !== 'capture' && (isset($result['TRANSACTIONID']) || isset($result['AUTHORIZATIONID']))) { $sql = ' UPDATE s_order SET transactionID=? WHERE transactionID=? LIMIT 1 '; $this->get('db')->query($sql, array(isset($result['TRANSACTIONID']) ? $result['TRANSACTIONID'] : $result['AUTHORIZATIONID'], $transactionId)); $transactionId = $result['TRANSACTIONID']; } if ($action == 'void') { $paymentStatus = 'Voided'; } elseif ($action == 'refund') { $paymentStatus = 'Refunded'; } elseif (isset($result['PAYMENTSTATUS'])) { $paymentStatus = $result['PAYMENTSTATUS']; } if (isset($paymentStatus)) { try { $this->plugin->setPaymentStatus($transactionId, $paymentStatus, $note); } catch (Exception $e) { $result['SW_STATUS_ERROR'] = $e->getMessage(); } } $this->View()->assign(array('success' => true, 'result' => $result)); } catch (Exception $e) { $this->View()->assign(array('message' => $e->getMessage(), 'success' => false)); } }
public function __construct(Bootstrap $bootstrap) { $this->bootstrap = $bootstrap; $this->config = $bootstrap->Config(); }
/** * save the invoice instructions from paypal * * @param string $orderNumber * @param array $payment */ private function saveInvoiceInstructions($orderNumber, array $payment) { $paymentInstructionProvider = new PaymentInstructionProvider($this->paypalBootstrap->get('db')); $paymentInstructionProvider->saveInstructionByOrderNumber($orderNumber, $payment['payment_instruction']); }