当前位置: 首页>>代码示例>>PHP>>正文


PHP MP::create_payment方法代码示例

本文整理汇总了PHP中MP::create_payment方法的典型用法代码示例。如果您正苦于以下问题:PHP MP::create_payment方法的具体用法?PHP MP::create_payment怎么用?PHP MP::create_payment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MP的用法示例。


在下文中一共展示了MP::create_payment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: payment

 public function payment()
 {
     $this->language->load('payment/mp_ticket');
     try {
         $this->load->model('checkout/order');
         $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
         $all_products = $this->cart->getProducts();
         $items = array();
         foreach ($all_products as $product) {
             $items[] = array("id" => $product['product_id'], "title" => $product['name'], "description" => $product['quantity'] . ' x ' . $product['name'], "quantity" => intval($product['quantity']), "unit_price" => round(floatval($product['price']), 2), "picture_url" => HTTP_SERVER . 'image/' . $product['image'], "category_id" => $this->config->get('mp_ticket_category_id'));
         }
         $payer = array("email" => $order_info['email']);
         $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $order_info['shipping_postcode'], "street_name" => $order_info['shipping_address_1'] . " - " . $order_info['shipping_address_2'] . " - " . $order_info['shipping_city'] . " - " . $order_info['shipping_zone'] . " - " . $order_info['shipping_country'], "apartment" => "-", "street_number" => "-"));
         $value = floatval(number_format(floatval($order_info['total']) * floatval($order_info['currency_value']), 2));
         $access_token = $this->config->get('mp_ticket_access_token');
         $mp = new MP($access_token);
         $payment_data = array("payer" => $payer, "external_reference" => $order_info['order_id'], "transaction_amount" => $value, "notification_url" => $order_info['store_url'] . 'index.php?route=payment/mp_ticket/notifications', "description" => 'Products', "payment_method_id" => $this->request->get['payment_method_id']);
         $payment_data['additional_info'] = array('shipments' => $shipments, 'items' => $items);
         $is_test_user = strpos($order_info['email'], '@testuser.com');
         if (!$is_test_user) {
             $payment_data["sponsor_id"] = $this->sponsors[$this->getCountry()];
         }
         $payment_response = $mp->create_payment($payment_data);
         error_log('payment response: ' . json_encode($payment_response));
         $this->model_checkout_order->addOrderHistory($order_info['order_id'], $this->config->get('mp_ticket_order_status_id'), null, false);
         echo json_encode(array("status" => $payment_response['status'], "url" => $payment_response['response']['transaction_details']['external_resource_url']));
     } catch (Exception $e) {
         error_log('deu erro: ' . $e);
         echo json_encode(array("status" => $e->getCode(), "message" => $e->getMessage()));
     }
 }
开发者ID:BrunoCodeman,项目名称:cart-opencart,代码行数:31,代码来源:mp_ticket.php

示例2: payment

 public function payment()
 {
     $this->language->load('payment/mp_transparente');
     error_log(json_encode($this->request->post));
     try {
         $exclude = $this->config->get('mp_transparente_methods');
         $accepted_methods = preg_split("/[\\s,]+/", $exclude);
         $payment_method_id = $this->request->post['payment_method_id'];
         $this->load->model('checkout/order');
         $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
         $all_products = $this->cart->getProducts();
         $items = array();
         foreach ($all_products as $product) {
             $product_price = floatval(number_format(floatval($product['price']) * floatval($order_info['currency_value']), 2));
             $items[] = array("id" => $product['product_id'], "title" => $product['name'], "description" => $product['quantity'] . ' x ' . $product['name'], "quantity" => intval($product['quantity']), "unit_price" => $product_price, "picture_url" => HTTP_SERVER . 'image/' . $product['image'], "category_id" => $this->config->get('mp_transparente_category_id'));
         }
         $payer = array("email" => $order_info['email']);
         if ($this->config->get("mp_transparente_country") != "MLM") {
             $payer['identification'] = array();
             $payer['identification']['type'] = $this->request->post['docType'];
             $payer['identification']["number"] = $this->request->post['docNumber'];
         }
         $shipments = array("receiver_address" => array("floor" => "-", "zip_code" => $order_info['shipping_postcode'], "street_name" => $order_info['shipping_address_1'] . " - " . $order_info['shipping_address_2'] . " - " . $order_info['shipping_city'] . " - " . $order_info['shipping_zone'] . " - " . $order_info['shipping_country'], "apartment" => "-", "street_number" => "-"));
         $value = number_format(floatval($order_info['total']) * floatval($order_info['currency_value']), 2);
         $access_token = $this->config->get('mp_transparente_access_token');
         $payment_data = array("payer" => $payer, "external_reference" => $order_info['order_id'], "transaction_amount" => floatval($value), "notification_url" => $order_info['store_url'] . 'index.php?route=payment/mp_transparente/notifications', "token" => $this->request->post['token'], "description" => 'Products', "installments" => (int) $this->request->post['installments'], "payment_method_id" => $this->request->post['payment_method_id']);
         $payment_data['additional_info'] = array('shipments' => $shipments, 'items' => $items);
         $payment_data['metadata'] = array('token' => $payment_data['token']);
         $is_test_user = strpos($order_info['email'], '@testuser.com');
         if (!$is_test_user) {
             $sponsor_id = $this->sponsors[$this->config->get('mp_transparente_country')];
             error_log('not test_user. sponsor_id will be sent: ' . $sponsor_id);
             $payment_data["sponsor_id"] = $sponsor_id;
         } else {
             error_log('test_user. sponsor_id will not be sent');
         }
         if (isset($this->request->post['issuer_id']) && strlen($this->request->post['issuer_id']) > 0) {
             error_log('issuer_id set, will be sent: ' . $this->request->post['issuer_id']);
             $payment_data['issuer_id'] = $this->request->post['issuer_id'];
         } else {
             error_log('issuer_id NOT set, will NOT be sent');
             unset($payment_data['issuer_id']);
         }
         $payment_json = json_encode($payment_data);
         error_log("pagamento: " . $payment_json);
         $accepted_status = array('approved', "in_process");
         $mp = new MP($access_token);
         $payment_response = $mp->create_payment($payment_json);
         error_log("pagamento processado: ");
         error_log($payment_json);
         error_log("------------------------------------------------------------- payment status: " . $payment_response['response']['status']);
         error_log("payment send:");
         error_log(json_encode($payment_data));
         error_log("payment received");
         error_log(json_encode($payment_response));
         $this->model_checkout_order->addOrderHistory($order_info['order_id'], $this->config->get('mp_transparente_order_status_id_pending'), date('d/m/Y h:i') . ' - ' . $payment_data['payment_method_id']);
         $this->updateOrder($payment_response['response']['id']);
         $json_response = array('status' => null, 'message' => null);
         if (in_array($payment_response['response']['status'], $accepted_status)) {
             $json_response['status'] = $payment_response['response']['status'];
         } else {
             $json_response['status'] = $payment_response['response']['status_detail'];
         }
         echo json_encode($json_response);
     } catch (Exception $e) {
         echo json_encode(array("status" => $e->getCode(), "message" => $e->getMessage()));
     }
 }
开发者ID:BrunoCodeman,项目名称:cart-opencart,代码行数:68,代码来源:mp_transparente.php


注:本文中的MP::create_payment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。