Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/era/pay
Pay is an Elixir Lib to deal with Paypal and other payment solutions.
https://github.com/era/pay
Last synced: about 1 month ago
JSON representation
Pay is an Elixir Lib to deal with Paypal and other payment solutions.
- Host: GitHub
- URL: https://github.com/era/pay
- Owner: era
- Created: 2015-09-30T21:13:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-23T11:41:57.000Z (about 7 years ago)
- Last Synced: 2024-04-22T13:34:00.384Z (8 months ago)
- Language: Elixir
- Size: 43.9 KB
- Stars: 26
- Watchers: 2
- Forks: 11
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - An Elixir Lib to deal with Paypal and other payment solutions. (Third Party APIs)
- fucking-awesome-elixir - pay - An Elixir Lib to deal with Paypal and other payment solutions. (Third Party APIs)
- awesome-elixir - pay - An Elixir Lib to deal with Paypal and other payment solutions. (Third Party APIs)
README
![](eric.jpeg)
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):
```elixir
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:
```elixir
# 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`
```elixir
config :pay, type: :paypal
```
And also your key from paypal:
```elixir
config :pay, :paypal,
client_id: "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp",
secret: "EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp",
env: :prod
```In your mix file:
```elixir
def deps do
[{:pay, github: "era/pay"}]
enddef application do
[applications: [:pay]]
end
```Phoenix + Pay
----
If you want an example of how to use it, take a look at [era/extip](http://www.github.com/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 RequestTODO
---
* Support all Paypal API.
* Add pagar.me support.
* Add pagseguro support.License
-----
MIT