Giter Site home page Giter Site logo

pay's Introduction

Pay

Pay is an Elixir Lib to deal with Paypal and other payment solutions. The lib's main goal is to be easy to extend other payment solutions.

It also uses Maru to receive the callback from the payment, so you don't need to worry about it. Just add the function that you want to run everytime that a payment is confirmed (or denied). {TODO}

Usage

Creating a Payment (you must use the PaypalPayment struct):

Payment.create_payment(%Paypal.Payment{intent: "authorize", payer: %{"funding_instruments" => [%{"credit_card" => %{"billing_address" => %{"city" => "Saratoga", "country_code" => "US", "line1" => "111 First Street", "postal_code" => "95070", "state" => "CA"}, "cvv2" => "874", "expire_month" => 11, "expire_year" => 2018, "first_name" => "Betsy", "last_name" => "Buyer", "number" => "4417119669820331", "type" => "visa"}}], "payment_method" => "credit_card"}, transactions: [%{"amount" => %{"currency" => "USD", "details" => %{"shipping" => "0.03", "subtotal" => "7.41", "tax" => "0.03"}, "total" => "7.47"}, "description" => "This is the payment transaction description."}]})

or if using Paypal as the payment method:

# create payment
payment = Payment.create_payment(%Paypal.Payment{
  intent: "sale",
  payer: %{"payment_method" => "paypal"},
  transactions: [%{"amount" => %{"currency" => "USD", "details" => %{"shipping" => "0.03", "subtotal" => "7.41", "tax" => "0.03"}, "total" => "7.47"}, "description" => "This is the payment transaction description."}],
  redirect_urls: %{"return_url" => "http://YOUR_RETURN_URL", "cancel_url" => "http://YOUR_CANCEL_URL"}
})
approval_url = Enum.find(payment["links"], fn (x) -> x["rel"] == "approval_url" and x["method"] == "REDIRECT" end)
# redirect user to approval_url["href"]
# after user has approved the payment, we can execute it on return url call.
Payment.execute_payment(%Paypal.Payment{id: "PAYMENT_ID_FROM_RETURN_CALL", payer: %{id: "PAYER_ID_FROM_RETURN_CALL"}})

then add the pay to your config/config.exs

config :pay, type: :paypal

And also your key from paypal:

config :pay, :paypal,
  client_id: "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp",
  secret: "EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp",
  env: :prod

In your mix file:

def deps do
  [{:pay, github: "era/pay"}]
end


def application do
  [applications: [:pay]]
end

Phoenix + Pay

If you want an example of how to use it, take a look at era/extip. It's a very simple example of how to use pay with Phoenix Apps.

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Create a Pull Request

TODO

  • Support all Paypal API.
  • Add pagar.me support.
  • Add pagseguro support.

License

MIT

pay's People

Contributors

denic avatar era avatar huangjun604 avatar kathgironpe avatar waffle-iron avatar webdeb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pay's Issues

Process is not alive

Hello! I tried following the instructions the README file. I have no luck in making it work.

When I execute this command:

payment = %Paypal.Payment{
      intent: "sale",
      payer: %{"payment_method" => "paypal"},
      transactions: [%{"amount" => %{"currency" => "USD", "details" => %{"shipping" => "0.03", "subtotal" => "7.41", "tax" => "0.03"}, "total" => "7.47"}, "description" => "This is the payment transaction description."}],
      redirect_urls: %{"return_url" => "http://google.com", "cancel_url" => "http://google.com"}
    }
    Payment.create_payment(payment)

I receive this error:

[error] Task #PID<0.893.0> started from #PID<0.888.0> terminating
** (stop) exited in: GenServer.call(:token, {:get, #Function<2.36722068/1 in Paypal.Authentication.is_expired/0>}, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (elixir) lib/gen_server.ex:766: GenServer.call/3
    (pay) lib/paypal/authentication.ex:27: Paypal.Authentication.is_expired/0
    (pay) lib/paypal/authentication.ex:16: Paypal.Authentication.get_token/0
    (pay) lib/paypal/authentication.ex:60: Paypal.Authentication.authorization_header/0
    (pay) lib/paypal/authentication.ex:53: Paypal.Authentication.headers/0
    (pay) lib/paypal/payment.ex:42: Payment.Paypal.Payment.do_create_payment/1
    (elixir) lib/task/supervised.ex:85: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:36: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Function: #Function<0.63762606/0 in Payment.Paypal.Payment.create_payment/1>
    Args: []
[error] Ranch protocol #PID<0.888.0> (:cowboy_protocol) of listener KnvapiExWeb.Endpoint.HTTP terminated
** (exit) exited in: GenServer.call(:token, {:get, #Function<2.36722068/1 in Paypal.Authentication.is_expired/0>}, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

Thanks!

Access Token refresh broken

Hi, I encountered an error that gives me a really weird error message from PayPal (http://stackoverflow.com/questions/38603625/paypal-java-future-payment-obtain-refresh-token).

It looks like they updated their API and now the access token refresh does not work any longer.

Also I already fixed it, I did not submit a pull request because I accidentally committed my mix.lock, that you may not want to have in your repo and I do not want to pollute your commit history. But you can find my changes here:

https://github.com/denic/pay/commit/75160aedec6f3c0fe56e9972caeaf9b9fdbae601

Integração com Pagar.me

@era tudo bem meu caro?

Alguém te respondeu sobre a integração da nossa API em modo sandbox? Se não, só para registrar: temos este ambiente sim, basta fazer um cadastro em nossa Dashboard que automaticamente será criada uma api_key de testes: https://dashboard.pagar.me/#/signup?sid=1002

Com esta chave de testes é possível testar quase que todos os fluxos da nossa aplicação, é bem legal.

Um abração!

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.