Giter VIP home page Giter VIP logo

spreedly-elixir's Introduction

Spreedly Hex pm hex.pm downloads

A wrapper of the Spreedly API (documentation). This library is not officially supported.

Installation

The package can be installed by adding spreedly to your list of dependencies in mix.exs:

def deps do
  [{:spreedly, "~> 2.0.0"}]
end

Add it to your application dependency:

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

Configuration

Spreedly Elixir has a limited number of configuration options that you can override in your project specific configuration files. The options include specifying the receive timeout.

config :spreedly,
  receive_timeout: value  # Defaults to 10_000 milliseconds

Usage

API interactions happen with a Spreedly.Environment.

env = Spreedly.Environment.new(environment_key, access_secret)

Once you have an environment, you can use it to interact with the API.

Run a purchase using a credit card

You can pattern match on the response.

case Spreedly.purchase(env, "R8AKGmYwkZrrj2BpWcPge", "RjTFFZQp4MrH2HJNfPwK", 2344) do
  {:ok, %{succeeded: true}} ->
    IO.puts "Success!"
  {:ok, %{succeeded: false, message: message}} ->
    IO.puts "Declined - #{message}!"
  {:error, reason} ->
    IO.inspect reason
end

Show a Transaction

iex> Spreedly.show_transaction(env, "TcsSf0hpfa3K3zW5eYdSOQmR0rs")
{:ok,
 %{created_at: "2016-01-10T16:36:14Z", currency_code: nil, description: nil,
   email: nil, gateway_specific_fields: nil,
   gateway_specific_response_fields: %{},
   gateway_token: "LJzOP1BwPkmgmiieHKpNT5xmqyU", gateway_transaction_id: nil,
   ip: nil, merchant_location_descriptor: nil, merchant_name_descriptor: nil,
   message: "Unable to process the verify transaction.", on_test_gateway: true,
   order_id: nil,
   payment_method: %{first_name: "Matrim", storage_state: "cached",
     first_six_digits: "401288", shipping_phone_number: nil, card_type: "visa",
     company: nil, number: "XXXX-XXXX-XXXX-1881", shipping_address1: nil,
     token: "IRfuy5hKmBpu4bqCHdPE621uEac", state: nil, year: 2019,
     fingerprint: "7d59b8215d44351c9a9801fbe61b0e8e4657",
     full_name: "Matrim Cauthon", updated_at: "2016-01-10T16:36:14Z",
     errors: [], phone_number: nil, shipping_country: nil,
     verification_value: "", data: nil, city: nil, shipping_city: nil,
     last_four_digits: "1881", last_name: "Cauthon",
     eligible_for_card_updater: nil, shipping_address2: nil, zip: nil,
     country: nil, test: true, shipping_zip: nil, email: "[email protected]",
     shipping_state: nil, month: 1, created_at: "2016-01-10T16:36:14Z",
     payment_method_type: "credit_card", ...},
   response: %{avs_code: nil, avs_message: nil, cancelled: false,
     created_at: "2016-01-10T16:36:14Z", cvv_code: nil, cvv_message: nil,
     error_code: "", error_detail: nil, fraud_review: nil,
     message: "Unable to process the verify transaction.", pending: false,
     result_unknown: false, success: false, updated_at: "2016-01-10T16:36:14Z"},
   response_body: "{\"transaction\":{\"on_test_gateway\":true,\"created_at\":\"2016-01-10T16:36:14Z\",\"updated_at\":\"2016-01-10T16:36:14Z\",\"succeeded\":false,\"state\":\"gateway_processing_failed\",\"token\":\"8A8vvB2RbbL41CRz7YYUbAQW5Yw\",\"transaction_type\":\"Verification\",\"order_id\":null,\"ip\":null,\"description\":null,\"email\":null,\"merchant_name_descriptor\":null,\"merchant_location_descriptor\":null,\"gateway_specific_fields\":null,\"gateway_specific_response_fields\":{},\"gateway_transaction_id\":null,\"currency_code\":null,\"retain_on_success\":null,\"message\":\"Unable to process the verify transaction.\",\"gateway_token\":\"LJzOP1BwPkmgmiieHKpNT5xmqyU\",\"response\":{\"success\":false,\"message\":\"Unable to process the verify transaction.\",\"avs_code\":null,\"avs_message\":null,\"cvv_code\":null,\"cvv_message\":null,\"pending\":false,\"result_unknown\":false,\"error_code\":\"\",\"error_detail\":null,\"cancelled\":false,\"fraud_review\":null,\"created_at\":\"2016-01-10T16:36:14Z\",\"updated_at\":\"2016-01-10T16:36:14Z\"},\"shipping_address\":{\"name\":\"Matrim Cauthon\",\"address1\":null,\"address2\":null,\"city\":null,\"state\":null,\"zip\":null,\"country\":null,\"phone_number\":null},\"payment_method\":{\"token\":\"IRfuy5hKmBpu4bqCHdPE621uEac\",\"created_at\":\"2016-01-10T16:36:14Z\",\"updated_at\":\"2016-01-10T16:36:14Z\",\"email\":\"[email protected]\",\"data\":null,\"storage_state\":\"cached\",\"test\":true,\"last_four_digits\":\"1881\",\"first_six_digits\":\"401288\",\"card_type\":\"visa\",\"first_name\":\"Matrim\",\"last_name\":\"Cauthon\",\"month\":1,\"year\":2019,\"address1\":null,\"address2\":null,\"city\":null,\"state\":null,\"zip\":null,\"country\":null,\"phone_number\":null,\"company\":null,\"full_name\":\"Matrim Cauthon\",\"eligible_for_card_updater\":null,\"shipping_address1\":null,\"shipping_address2\":null,\"shipping_city\":null,\"shipping_state\":null,\"shipping_zip\":null,\"shipping_country\":null,\"shipping_phone_number\":null,\"payment_method_type\":\"credit_card\",\"errors\":[],\"fingerprint\":\"7d59b8215d44351c9a9801fbe61b0e8e4657\",\"verification_value\":\"\",\"number\":\"XXXX-XXXX-XXXX-1881\"}}}",
   retain_on_success: nil,
   shipping_address: %{address1: nil, address2: nil, city: nil, country: nil,
     name: "Matrim Cauthon", phone_number: nil, state: nil, zip: nil},
   state: "gateway_processing_failed", succeeded: false,
   token: "TcsSf0hpfa3K3zW5eYdSOQmR0rs", transaction_type: "Verification",
   updated_at: "2016-01-10T16:36:14Z"}}

iex> Spreedly.find_transaction(env, "NonExistentToken")
{:error, "Unable to find the transaction NonExistentToken."}

Contributing

We're happy to consider pull requests.

To help ensure a consistent code style and passing tests, we ask that you execute script/test before submitting the PR. The test script runs Credo, Dialyzer and the remote test suite. To run the remote test suite, the config/test.secret.exs file must have valid Spreedly credentials:

config :spreedly,
  environment_key: "<Your Environment Key>",
  access_secret: "<Your Access Secret>"

Example script/test output

# Run Credo, Dialyzer and remote tests
script/test

# Output
Checking 5 source files ...

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.4 seconds (0.02s to load, 0.4s running checks)
79 mods/funs, found no issues.

Checking PLT...
...
PLT is up to date!
Starting Dialyzer
...
done in 0m4.14s
done (passed successfully)

Compiling 6 files (.ex)
Generated spreedly app
Including tags: [:remote]
Excluding tags: [remote: true]

..............................................................................

Finished in 9.8 seconds
78 tests, 0 failures

Randomized with seed 25230

spreedly-elixir's People

Contributors

directionalpad avatar duff avatar jknipp avatar knewter avatar thalagyrt avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

spreedly-elixir's Issues

API credential leakage

Hiya,

You have live Spreedly API credentials committed to config/test.exs. I'm assuming this isn't a live Spreedly account, but it still gives people access to your Spreedly account which is less than ideal. I noticed this while running tests and wondering how anything was actually passing since it all appears to make live HTTP requests. I'd recommend revoking these credentials.

Cheers,
James

Error in Spreedly.Base process_response never matches. (Critical)

So it looks like the spreedly elixir library might be broken. It was working for us until today.

Screen Shot 2020-01-24 at 3 43 42 PM

it looks like the httpoison response in Spreedly.Base never matches parse_response. i threw a debugger and the api_request method in the Base module returns only an HTTPoison Struct. It doesn't return an ok or error tuple which parse_response expects.

i put in a catch all at the bottom

defp process_response(error) do IO.inspect(error) end

which just returns a %HTTPoison.Response{} instead of {_status, %HTTPoison.Response{}}

Using HTTPoison 1.6.2 in according to mix.lock

Add invocation style that requires parameters on each call

Hello, I've recently stumbled upon your library. Unofficial or not, it's under the hat of Spreedly so I'm very interested in using it.

That being said, going through the README I noticed you're storing the credentials in an Environment struct and then you require that struct in order to call operations.

I'm not gonna argue OOP vs. FP here because it's a matter of taste -- but would you be open to add wrappers to your Environment functions, directly in the Spreedly module? Something like this:

defmodule Spreedly do
  ...
  def purchase(key, secret, ...) do
    Spreedly.Environment.new(key, secret).purchase(...)
  end
  ...
end

I'd personally would be much more comfortable using it with more concise calls (only using Spreedly. as a prefix) and being able to do so statelessly (not storing credentials in objects between requests).

If you like the idea, you might not just add wrappers but simply change the core style to this? Up to you.

Additional food for thought might be adding bang functions (purchase!) which do the pattern matching internally and raise an error when the {:error, reason} tuple is returned.

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.