/** * Get the payment url * * @param OrderInterface $order * @return string url */ public function getPaymentURL(OrderInterface $order) { $icepay_config = \Drupal::config("uc_icepay.settings"); $country = $icepay_config->get("country"); $language = $icepay_config->get("language"); $merchant_id = $icepay_config->get("merchant_id"); $secret_code = $icepay_config->get("secret_code"); $protocol = $icepay_config->get("https_protocol"); $paymentObj = new \Icepay_PaymentObject(); $paymentObj->setOrderID($order->id() . date('is'))->setReference($order->id())->setAmount(intval($order->getTotal() * 100))->setCurrency($order->getCurrency())->setCountry($country)->setLanguage($language); $payment_plugin_id = IcepayApi::getPaymentPluginId($order->getPaymentMethodId()); $payment_method = IcepayApi::paymentPluginToIcepayPaymentMethod($payment_plugin_id); $paymentObj->setPaymentMethod($payment_method); if (isset($order->payment_details['ideal_issuer'])) { $paymentObj->setIssuer($order->payment_details['ideal_issuer']); } $basicmode = \Icepay_Basicmode::getInstance(); $basicmode->setMerchantID($merchant_id)->setSecretCode($secret_code)->validatePayment($paymentObj); $protocol = $protocol == true ? 'https' : 'http'; $basicmode->setProtocol($protocol); return $basicmode->getURL(); }
/** * {@inheritdoc} */ public function buildRedirectForm(array $form, FormStateInterface $form_state, OrderInterface $order = NULL) { $country = \Drupal::service('country_manager')->getCountry($order->getAddress('billing')->country); $data = array('sid' => $this->configuration['sid'], 'mode' => '2CO', 'card_holder_name' => Unicode::substr($order->getAddress('billing')->first_name . ' ' . $order->getAddress('billing')->last_name, 0, 128), 'street_address' => Unicode::substr($order->getAddress('billing')->street1, 0, 64), 'street_address2' => Unicode::substr($order->getAddress('billing')->street2, 0, 64), 'city' => Unicode::substr($order->getAddress('billing')->city, 0, 64), 'state' => $order->getAddress('billing')->zone, 'zip' => Unicode::substr($order->getAddress('billing')->postal_code, 0, 16), 'country' => $country ? $country->getAlpha3() : 'USA', 'email' => Unicode::substr($order->getEmail(), 0, 64), 'phone' => Unicode::substr($order->getAddress('billing')->phone, 0, 16), 'purchase_step' => 'payment-method', 'demo' => $this->configuration['demo'] ? 'Y' : 'N', 'lang' => $this->configuration['language'], 'merchant_order_id' => $order->id(), 'pay_method' => 'CC', 'x_receipt_link_url' => Url::fromRoute('uc_2checkout.complete', ['cart_id' => \Drupal::service('uc_cart.manager')->get()->getId()], ['absolute' => TRUE])->toString(), 'total' => uc_currency_format($order->getTotal(), FALSE, FALSE, '.'), 'currency_code' => $order->getCurrency(), 'cart_order_id' => $order->id()); $i = 0; foreach ($order->products as $product) { $i++; $data['li_' . $i . '_type'] = 'product'; $data['li_' . $i . '_name'] = $product->title->value; // @todo: HTML escape and limit to 128 chars $data['li_' . $i . '_quantity'] = $product->qty->value; $data['li_' . $i . '_product_id'] = $product->model->value; $data['li_' . $i . '_price'] = uc_currency_format($product->price->value, FALSE, FALSE, '.'); } if ('direct' == $this->configuration['checkout_type']) { $form['#attached']['library'][] = 'uc_2checkout/2checkout.direct'; } $form['#action'] = $this->configuration['server_url']; foreach ($data as $name => $value) { $form[$name] = array('#type' => 'hidden', '#value' => $value); } $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit order')); return $form; }