public function pay($id) { \PagSeguroLibrary::init(); \PagSeguroConfig::setEnvironment('production'); $this->plan = Plans::find($id); $this->client = User::find(Auth::user()->id); $this->payment = Payments::create(['plan_name' => $this->plan->name, 'plan_value' => $this->plan->value, 'plan_id' => $this->plan->id, 'user_id' => $this->client->id, 'confirmed' => 0]); // Instantiate a new payment request $paymentRequest = new \PagSeguroPaymentRequest(); // Set the currency $paymentRequest->setCurrency("BRL"); /* // Add an item for this payment request $paymentRequest->addItem('0001', 'Sempre da Negócio - Plano '.$this->plan->name, 1, $this->plan->value);*/ $paymentRequest->addItem($this->plan->id, 'Sempre da Negócio - Plano ' . $this->plan->name, 1, $this->plan->value); // Set a reference code for this payment request. It is useful to identify this payment // in future notifications. $paymentRequest->setReference($this->payment->id); //Create object PagSeguroShipping $shipping = new \PagSeguroShipping(); //Set Type Shipping $type = new \PagSeguroShippingType(3); $shipping->setType($type); //Set address of client $data = array('postalCode' => $this->client->zipcode, 'street' => $this->client->address, 'number' => $this->client->number, 'city' => $this->client->city, 'state' => $this->client->state); $address = new \PagSeguroAddress($data); $shipping->setAddress($address); //Add Shipping to Payment Request $paymentRequest->setShipping($shipping); // Set your customer information. $phone = str_replace(['(', ')', ' ', '-'], ['', '', '', ''], $this->client->phone); $paymentRequest->setSender($this->client->name, $this->client->email_responsible, substr($phone, 0, 2), substr($phone, 2)); try { /* * #### Credentials ##### * Replace the parameters below with your credentials (e-mail and token) * You can also get your credentials from a config file. See an example: * $credentials = PagSeguroConfig::getAccountCredentials(); // */ $credentials = new \PagSeguroAccountCredentials($this->email, $this->token); // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer. $onlyCheckoutCode = true; $code = $paymentRequest->register($credentials, $onlyCheckoutCode); return view('site.pages.confirma_pagamento', compact('code')); } catch (\PagSeguroServiceException $e) { die($e->getMessage()); } }
public function setShipping($address, $type = null) { $param = $address; if ($param instanceof PagSeguroShipping) { $this->shipping = $param; } else { $shipping = new PagSeguroShipping(); if (is_array($param)) { $shipping->setAddress(new PagSeguroAddress($param)); } else { if ($param instanceof PagSeguroAddress) { $shipping->setAddress($param); } } if ($type) { if ($type instanceof PagSeguroShippingType) { $shipping->setType($type); } else { $shipping->setType(new PagSeguroShippingType($type)); } } $this->shipping = $shipping; } }
/** * Generate PagSeguro Shipping Data * @return \PagSeguroShipping */ private function _generatePagSeguroShippingDataObject() { $shipping = new PagSeguroShipping(); $shipping->setAddress($this->_generatePagSeguroShippingAddressDataObject()); $shipping->setType($this->_generatePagSeguroShippingTypeObject()); $shipping->setCost(str_replace("R\$", '', $this->currency->format($this->_generatePagSeguroShippingCost(), $this->_order_info['currency_code'], false, false))); return $shipping; }
/** * @param $str_xml * @return PagSeguroTransaction */ public static function readTransaction($str_xml) { // Parser $parser = new PagSeguroXmlParser($str_xml); // <transaction> $data = $parser->getResult('transaction'); $transaction = new PagSeguroTransaction(); // <transaction> <lastEventDate> if (isset($data["lastEventDate"])) { $transaction->setLastEventDate($data["lastEventDate"]); } // <transaction> <date> if (isset($data["date"])) { $transaction->setDate($data["date"]); } // <transaction> <code> if (isset($data["code"])) { $transaction->setCode($data["code"]); } // <transaction> <reference> if (isset($data["reference"])) { $transaction->setReference($data["reference"]); } // <transaction> <type> if (isset($data["type"])) { $transaction->setType(new PagSeguroTransactionType($data["type"])); } // <transaction> <status> if (isset($data["status"])) { $transaction->setStatus(new PagSeguroTransactionStatus($data["status"])); } if (isset($data["paymentMethod"]) && is_array($data["paymentMethod"])) { // <transaction> <paymentMethod> $paymentMethod = new PagSeguroPaymentMethod(); // <transaction> <paymentMethod> <type> if (isset($data["paymentMethod"]['type'])) { $paymentMethod->setType(new PagSeguroPaymentMethodType($data["paymentMethod"]['type'])); } // <transaction> <paymentMethod> <code> if (isset($data["paymentMethod"]['code'])) { $paymentMethod->setCode(new PagSeguroPaymentMethodCode($data["paymentMethod"]['code'])); } $transaction->setPaymentMethod($paymentMethod); } // <transaction> <grossAmount> if (isset($data["grossAmount"])) { $transaction->setGrossAmount($data["grossAmount"]); } // <transaction> <discountAmount> if (isset($data["discountAmount"])) { $transaction->setDiscountAmount($data["discountAmount"]); } // <transaction> <feeAmount> if (isset($data["feeAmount"])) { $transaction->setFeeAmount($data["feeAmount"]); } // <transaction> <netAmount> if (isset($data["netAmount"])) { $transaction->setNetAmount($data["netAmount"]); } // <transaction> <extraAmount> if (isset($data["extraAmount"])) { $transaction->setExtraAmount($data["extraAmount"]); } // <transaction> <installmentCount> if (isset($data["installmentCount"])) { $transaction->setInstallmentCount($data["installmentCount"]); } if (isset($data["items"]['item']) && is_array($data["items"]['item'])) { $items = array(); $i = 0; if (isset($data["items"]['item'][0])) { foreach ($data["items"]['item'] as $key => $value) { $item = self::parseTransactionItem($value); $items[$i] = $item; $i++; } } else { $items[0] = self::parseTransactionItem($data["items"]['item']); } // <transaction> <items> $transaction->setItems($items); } if (isset($data["sender"])) { // <transaction> <sender> $sender = new PagSeguroSender(); // <transaction> <sender> <name> if (isset($data["sender"]["name"])) { $sender->setName($data["sender"]["name"]); } // <transaction> <sender> <email> if (isset($data["sender"]["email"])) { $sender->setEmail($data["sender"]["email"]); } if (isset($data["sender"]["phone"])) { // <transaction> <sender> <phone> $phone = new PagSeguroPhone(); // <transaction> <sender> <phone> <areaCode> if (isset($data["sender"]["phone"]["areaCode"])) { $phone->setAreaCode($data["sender"]["phone"]["areaCode"]); } // <transaction> <sender> <phone> <number> if (isset($data["sender"]["phone"]["number"])) { $phone->setNumber($data["sender"]["phone"]["number"]); } $sender->setPhone($phone); } // <transaction><sender><documents> if (isset($data['sender']['documents']) && is_array($data['sender']['documents'])) { $documents = $data['sender']['documents']; if (count($documents) > 0) { foreach ($documents as $document) { $sender->addDocument($document['type'], $document['value']); } } } $transaction->setSender($sender); } if (isset($data["shipping"]) && is_array($data["shipping"])) { // <transaction> <shipping> $shipping = new PagSeguroShipping(); // <transaction> <shipping> <type> if (isset($data["shipping"]["type"])) { $shipping->setType(new PagSeguroShippingType($data["shipping"]["type"])); } // <transaction> <shipping> <cost> if (isset($data["shipping"]["cost"])) { $shipping->setCost($data["shipping"]["cost"]); } if (isset($data["shipping"]["address"]) && is_array($data["shipping"]["address"])) { // <transaction> <shipping> <address> $address = new PagSeguroAddress(); // <transaction> <shipping> <address> <street> if (isset($data["shipping"]["address"]["street"])) { $address->setStreet($data["shipping"]["address"]["street"]); } // <transaction> <shipping> <address> <number> if (isset($data["shipping"]["address"]["number"])) { $address->setNumber($data["shipping"]["address"]["number"]); } // <transaction> <shipping> <address> <complement> if (isset($data["shipping"]["address"]["complement"])) { $address->setComplement($data["shipping"]["address"]["complement"]); } // <transaction> <shipping> <address> <city> if (isset($data["shipping"]["address"]["city"])) { $address->setCity($data["shipping"]["address"]["city"]); } // <transaction> <shipping> <address> <state> if (isset($data["shipping"]["address"]["state"])) { $address->setState($data["shipping"]["address"]["state"]); } // <transaction> <shipping> <address> <district> if (isset($data["shipping"]["address"]["district"])) { $address->setDistrict($data["shipping"]["address"]["district"]); } // <transaction> <shipping> <address> <postalCode> if (isset($data["shipping"]["address"]["postalCode"])) { $address->setPostalCode($data["shipping"]["address"]["postalCode"]); } // <transaction> <shipping> <address> <country> if (isset($data["shipping"]["address"]["country"])) { $address->setCountry($data["shipping"]["address"]["country"]); } $shipping->setAddress($address); } // <transaction> <shipping> $transaction->setShipping($shipping); } return $transaction; }
/** * Get the shipping information * @return PagSeguroShipping */ private function getShippingInformation() { $street = ""; $number = ""; $complement = ""; $district = ""; $fullAddress = $this->addressConfig($this->shippingData['street']); $street = $fullAddress[0] != '' ? $fullAddress[0] : $this->addressConfig($this->shippingData['street']); $number = is_null($fullAddress[1]) ? '' : $fullAddress[1]; $complement = is_null($fullAddress[2]) ? '' : $fullAddress[2]; $district = is_null($fullAddress[3]) ? '' : $fullAddress[3]; $PagSeguroShipping = new PagSeguroShipping(); $PagSeguroAddress = new PagSeguroAddress(); $PagSeguroAddress->setCity($this->shippingData['city']); $PagSeguroAddress->setPostalCode(self::fixPostalCode($this->shippingData['postcode'])); $PagSeguroAddress->setState($this->shippingData['region']); $PagSeguroAddress->setStreet($street); $PagSeguroAddress->setNumber($number); $PagSeguroAddress->setComplement($complement); $PagSeguroAddress->setDistrict($district); $PagSeguroShipping->setAddress($PagSeguroAddress); return $PagSeguroShipping; }
/** * Generates shipping data to PagSeguro transaction * * @return PagSeguroShipping */ private function _generateShippingData() { $shipping = new PagSeguroShipping(); $shipping->setAddress($this->_generateShippingAddressData()); $shipping->setType($this->_generateShippingType()); $shipping->setCost(number_format($this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), 2)); return $shipping; }
/** * Generates shipping data to PagSeguro transaction * @param stdClass $deliveryAddress * @param float $shippingCost * @return \PagSeguroShipping */ private function _generateShippingData($order) { $shipping = new PagSeguroShipping(); $shipping->setAddress($this->_generateShippingAddressData($order)); $shipping->setType($this->_generateShippingType()); $shipping->setCost(PagSeguroHelper::decimalFormat((double) $order->order_shipping_price)); return $shipping; }
/** * Generates shipping data to PagSeguro transaction * @param stdClass $deliveryAddress * @param float $shippingCost * @return \PagSeguroShipping */ private function _generateShippingData($deliveryAddress, $shippingCost) { $shipping = new PagSeguroShipping(); $shipping->setAddress($this->_generateShippingAddressData($deliveryAddress)); $shipping->setType($this->_generateShippingType()); $shipping->setCost(PagSeguroHelper::decimalFormat((double) $shippingCost)); return $shipping; }
/** * * @return PagSeguroShipping */ private function getShippingInformation() { $fileOSC = scandir(getcwd() . '/app/code/local/DeivisonArthur'); $street = ""; $number = ""; $complement = ""; $complement = ""; if (!$fileOSC) { $fullAddress = $this->_addressConfig($this->Shipping_Data['street']); $street = $fullAddress[0] != '' ? $fullAddress[0] : $this->_addressConfig($this->Shipping_Data['street']); $number = is_null($fullAddress[1]) ? '' : $fullAddress[1]; $complement = is_null($fullAddress[2]) ? '' : $fullAddress[2]; $complement = is_null($fullAddress[3]) ? '' : $fullAddress[3]; } $PagSeguroShipping = new PagSeguroShipping(); $PagSeguroAddress = new PagSeguroAddress(); $PagSeguroAddress->setCity($this->Shipping_Data['city']); $PagSeguroAddress->setPostalCode(self::fixPostalCode($this->Shipping_Data['postcode'])); $PagSeguroAddress->setState($this->Shipping_Data['region']); $PagSeguroAddress->setStreet($street); $PagSeguroAddress->setNumber($number); $PagSeguroAddress->setComplement($complement); $PagSeguroAddress->setDistrict($district); $PagSeguroShipping->setAddress($PagSeguroAddress); return $PagSeguroShipping; }
/** * Processa o formulário, */ function process_form() { //var_dump($_POST); //die(); require_once "PagSeguroLibrary/PagSeguroLibrary.php"; $id = $_POST['item_id']; $descricao = $_POST['item_descricao']; $qtd = $_POST['item_qtd']; $valor = $_POST['item_valor']; $peso = $_POST['item_peso']; $frete = $_POST['frete']; $valor = str_replace(",", ".", $valor); //Instancia uma requisicao de pagamento $paymentRequest = new PagSeguroPaymentRequest(); //Seta a moeda $paymentRequest->setCurrency("BRL"); //Adiciona os itens para gerar a url $paymentRequest->addItem($id, $descricao, $qtd, $valor, $peso); //Seta o ambiente de producao, se é Sandbox, ou production $is_sandbox = get_option('ps_config_enable_sandbox'); if (strlen($is_sandbox) > 0) { PagSeguroConfig::setEnvironment('sandbox'); $PagSeguroConfig['log']['active'] = TRUE; } else { PagSeguroConfig::setEnvironment('production'); } /* Infos seguintes apenas para referencia*/ // Add another item for this payment request //$paymentRequest->addItem('0002', 'Notebook rosa', 2, 1.00); // Sets a reference code for this payment request, it is useful to identify this payment in future notifications. //$paymentRequest->setReference($dadosComprador["codReference"]); // Sets shipping information for this payment request //$CODIGO_SEDEX = PagSeguroShippingType::getCodeByType('SEDEX'); //$paymentRequest->setShippingType($CODIGO_SEDEX); //$paymentRequest->setShippingAddress('30315230', 'Rua Zito Soares', '179', '', 'Mangabeiras', 'Belo Horizonte', 'MG', 'BRA'); /* Criando o tipo de frete */ $shippingType = new PagSeguroShippingType(); /* Definindo tipo de frete 'PAC' */ $shippingType->setByType('PAC'); $shipping = new PagSeguroShipping(); $shipping->setType($shippingType); $data = array('postalCode' => '01452002', 'street' => 'Av. Brig. Faria Lima', 'number' => '1384', 'complement' => 'apto. 114', 'district' => 'Jardim Paulistano', 'city' => 'São Paulo', 'state' => 'SP', 'country' => 'BRA'); $address = new PagSeguroAddress($data); // objeto PagSeguroAddress $shipping->setAddress($address); $type = $shipping->getType(); // Objeto PagSeguroShippingType $address = $shipping->getAddress(); // objeto PagSeguroAddress $cost = $shipping->getCost(); // Float $shipping->setCost($cost); /* $paymentRequest deve ser um objeto do tipo PagSeguroPaymentRequest */ $paymentRequest->setShipping($shipping); var_dump($shipping->setCost); die; // Sets your customer information. //$paymentRequest->setSender($dadosComprador["nome"] . ' ' . $dadosComprador["sobrenome"], $dadosComprador["email"]); //Seta a URL de retorno $paymentRequest->setRedirectUrl(get_option('ps_config_return_url')); try { //Inicializa as credenciais $credentials = new PagSeguroAccountCredentials(get_option('ps_config_auth_email'), get_option('ps_config_auth_token')); //obtem-se a URL da compra $url = $paymentRequest->register($credentials); //faz o redirect para a url do pagseguro wp_redirect($url); exit; } catch (PagSeguroServiceException $e) { die($e->getMessage()); } var_dump($dadosComprador); die; }