GithubHelp home page GithubHelp logo

pagseguro_client's Introduction

PAGSEGURO Client Build Status Code Climate Coverage Status

Este é um plugin do Ruby on Rails que permite utilizar o PagSeguro, gateway de pagamentos do UOL.

Changelog

Como usar

Instalação

Adicione a biblioteca ao arquivo Gemfile:

gem 'pagseguro_client'

Depois de realizar a instalação da biblioteca, você precisará gerar o arquivo de configuração, que deve residir em config/pagseguro.yml. Para gerar o arquivo a partir de um modelo execute

  rails generate pagseguro_client:install

O arquivo de configuração gerado será parecido com isso:

development: &development
  ws_url: "http://localhost:4000"
  ps_url: "http://localhost:4000"
  return_to: "http://localhost:4000/successo"
  email: [email protected]
  token: "tokenGeradoPeloPagseguro"

test:
  <<: *development

production:
  ws_url: "https://ws.pagseguro.uol.com.br"
  ps_url: "https://pagseguro.uol.com.br"
  return_to: "http://www.sualoja.com.br/successo"
  email: [email protected]
  token: "tokenGeradoPeloPagseguro"

Para realizar os testes de integração da sua aplicação com o gateway, você pode usar um servidor de testes desenvolvido pelo próprio Pagseguro: Pagseguro Server

Gerando a sua ordem de pagamento

@order = PagseguroClient::Order.new(id) # Seu identificador da ordem de pagamento
@order.add(
  id: "1", # Seu identificador do produto
  description: produto.descricao,
  amount: produto.preco)
@response = order.send_request

Exemplo de resposta da ordem de pagamento

# Hash
{
  code: "8CF4BE7DCECEF0F004A6DFA0A8243412",
  url: "https://ws.pagseguro.uol.com.br/v2/checkout/payment.html?code=8CF4BE7DCECEF0F004A6DFA0A8243412"
}

Agora basta usar a url retornada para enviar o usuário para efetuar o pagamento no site do Pagseguro.

Configurando opção para URL de retorno dinâmica

Para configurar uma URL de retorno dinâmica a sua aplicação Rails, basta adicionar ao arquivo pagseguro.yml a opção return_to com o endereço para retorno que você configurou na sua aplicação:

production:
  ws_url: "https://ws.pagseguro.uol.com.br"
  ps_url: "https://pagseguro.uol.com.br"
  return_to: "http://www.sualoja.com.br/sucesso"
  email: [email protected]
  token: "tokenGeradoPeloPagseguro"

Obtendo as notificações

# No seu controller
def notificacao
  return unless request.post?

  @notification = PagseguroClient::Notification.retrieve(params[:notificationCode])
  # Seu código para utilizar a notificação

  render nothing: true
end

O objeto notification possui os seguintes métodos:

  • PagseguroClient::Notification#code: Código da notificação
  • PagseguroClient::Notification#order_id: Código da sua ordem de pagamento
  • PagseguroClient::Notification#status: Status da ordem de pagamento atual
  • PagseguroClient::Notification#payment_method: Método utilizado para o pagamento
  • PagseguroClient::Notification#client: Dados do comprador
  • PagseguroClient::Notification#address: Endereço do comprador

Consultando Transações

# No seu controller
def complete

  @transaction = PagseguroClient::Transaction.retrieve(params[:transaction_id_])
  # Seu código para utilizar a transaction
end

O objeto transaction possui os seguintes métodos:

  • PagseguroClient::Transaction#code: Código da notificação
  • PagseguroClient::Transaction#order_id: Código da sua ordem de pagamento
  • PagseguroClient::Transaction#status: Status da ordem de pagamento atual
  • PagseguroClient::Transaction#payment_method: Método utilizado para o pagamento
  • PagseguroClient::Transaction#client: Dados do comprador
  • PagseguroClient::Transaction#address: Endereço do comprador

Métodos de pagamento

  • credit_card: Cartão de crédito
  • invoice: Boleto
  • online_transfer: Pagamento online
  • pagseguro: Transferência entre contas do PagSeguro
  • oi_paggo: Oi Paggo :)

Status

  • pending: Aguardando pagamento
  • verifying: Em análise
  • approved: Aprovado
  • available: Disponível
  • refunded: Devolvido
  • canceled: Cancelado

Autor

Licença (MIT):

Mais informações no arquivo LICENSE.txt

pagseguro_client's People

Contributors

fknappe avatar kupkovski avatar matheustardivo avatar pickachu avatar raphaelcosta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pagseguro_client's Issues

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Adição de atributos de frete no objeto de transação

A implementação parece trivial:

# on class
SHIPPING_TYPE = {
  1 => :pac
  2 => :sedex
}

attr_accessor :code, :order_id, :status, :payment_method, :last_event_date, :sender, :address, :shipping

# on #self.create_by_xml

shipping = {
  type: doc.xpath("//transaction/shipping/type").text
  cost: doc.xpath("//transaction/shipping/cost").text
}

transaction = Transaction.new(

  

  address: address,
  last_event_date: last_event_date
  shipping: shipping
)

Alguém se habilita a fazer? Se me derem permissão eu também envio pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.