{"id":32172802,"url":"https://github.com/ygunayer/craftgate-elixir-client","last_synced_at":"2025-12-11T23:42:09.832Z","repository":{"id":176043704,"uuid":"584286668","full_name":"ygunayer/craftgate-elixir-client","owner":"ygunayer","description":"Elixir client for Craftgate API","archived":false,"fork":false,"pushed_at":"2023-10-06T14:28:38.000Z","size":90,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-26T16:56:48.612Z","etag":null,"topics":["craftgate","craftgate-api","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ygunayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-02T05:39:36.000Z","updated_at":"2023-06-17T10:10:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6c30d2c-c954-4e10-b7e1-8b6bf7976212","html_url":"https://github.com/ygunayer/craftgate-elixir-client","commit_stats":null,"previous_names":["ygunayer/craftgate-elixir-client","ygunayer/craftgate-elixir"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ygunayer/craftgate-elixir-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygunayer%2Fcraftgate-elixir-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygunayer%2Fcraftgate-elixir-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygunayer%2Fcraftgate-elixir-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygunayer%2Fcraftgate-elixir-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ygunayer","download_url":"https://codeload.github.com/ygunayer/craftgate-elixir-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ygunayer%2Fcraftgate-elixir-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280317271,"owners_count":26309997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["craftgate","craftgate-api","elixir"],"created_at":"2025-10-21T18:44:07.335Z","updated_at":"2025-10-21T18:44:11.563Z","avatar_url":"https://github.com/ygunayer.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Hex pm](https://img.shields.io/hexpm/v/craftgate.svg?style=flat)](https://hex.pm/packages/craftgate) [![Coverage Status](https://coveralls.io/repos/github/ygunayer/craftgate-elixir-client/badge.svg?branch=main)](https://coveralls.io/github/ygunayer/craftgate-elixir-client?branch=main)\n\n# Craftgate\nThis repo contains the Elixir client for Craftgate API.\n\n## Requirements\n- Elixir `1.12` or newer\n\n## Dependencies\n- [HTTPoison](https://github.com/edgurgel/httpoison/) to execute requests\n- [Jason](https://github.com/michalmuskala/jason) for JSON serialization/deserialization\n- [Construct](https://github.com/ExpressApp/construct) to provide a concise interface for representing request/response payloads as Elixir structs while also having them converted automatically by Jason\n- [Decimal](https://github.com/ericmj/decimal) to represent monetary values\n- [Recase](https://github.com/wemake-services/recase) to convert between Craftgate API's `camelCase` and Elixir's `snake_case`\n\n\u003e **Note:** To keep the correct precision without losing any information, all decimals are serialized into *strings*. Since Craftgate API uses Java's `BigDecimal` to process these values it has no trouble parsing them, and likewise, by using Construct, Jason and Decimal in conjunction we're able to parse both numerical and string representations of decimals.\n\n## Installation\nAdd the `:craftgate` dependency to your `mix.exs` file\n\n```elixir\ndef deps do\n  ...\n  {:craftgate, \"~\u003e 1.0.42\"}\n  ...\nend\n```\n\n## Configuration\nTo access the Craftgate API you'll first need to obtain a set of API credentials. If you don't already have a Craftgate account, you can signup at [https://craftgate.io](https://craftgate.io), and after the onboarding process you will be able to access your API credentials from the merchant panel.\n\nOnce you've obtained your API credentials, you can configure Craftgate through the `:craftgate` on your `config.exs` file.\n\n```elixir\nconfig :craftgate,\n  api_key: \"\u003cYOUR API KEY\u003e\",\n  secret_key: \"\u003cYOUR SECRET KEY\u003e\"\n```\n\nBy default, Craftgate will run in sandbox mode and connect to the sandbox API at [https://sandbox-api.craftgate.io](https://sandbox-api.craftgate.io).\n\nOnce you're confident with your implementation you can swap out the `base_url` parameter with the live production URL at [https://api.craftgate.io](https://api.craftgate.io)\n\n```elixir\nconfig :craftgate,\n  api_key: \"\u003cYOUR API KEY\u003e\",\n  secret_key: \"\u003cYOUR SECRET KEY\u003e\",\n  base_url: \"https://api.craftgate.io\"\n```\n\nAdditionally, Craftgate will use English as the default locale (`\"en\"`) when contacting the Craftgate API, and also set a few request options to disable redirections and set particular request and receive timeouts. You can override these configurations by changing the `lang` and `request_options` keys respectively.\n\nDo note, however, that by overriding `request_options`, you will be losing the default request options, so don't forget to include them if you only wish to add more parameters. For a list of all available options, see [the documentation for HTTPoison.Request](https://hexdocs.pm/httpoison/HTTPoison.Request.html)\n\nBelow is the list of default request options:\n\n```elixir\n[\n  timeout: 10_000,\n  recv_timeout: 150_000,\n  max_redirect: 0,\n  follow_redirect: false\n]\n```\n\n\u003e **Note:** You can also override these values by passing them to any Craftgate API call (e.g. `Craftgate.Adapter.PaymentReportingAdapter.retrieve_payment(1, request_options: [timeout: 100_000]`)\n\nSo with that, a fully customized Craftgate configuration can look something like below:\n\n```elixir\nconfig :craftgate,\n  api_key: \"\u003cYOUR API KEY\u003e\",\n  secret_key: \"\u003cYOUR SECRET KEY\u003e\",\n  base_url: \"https://api.craftgate.io\",\n  lang: \"tr\",\n  request_options: [\n    timeout: 60_000,\n    recv_timeout: 120_000,\n    max_redirect: 1,\n    follow_redirect: true\n  ]\n```\n\n### Environment-Specific Configuration\nAs with any Phoenix app you can also make use of the environment-specific files to configure Craftgate for your development and production environments. In fact, we highly recommend inferring the production API credentials from environment variables in production and not have them written out plainly in your codebase.\n\n**config/config.exs**\n```elixir\n...\nconfig :craftgate,\n  base_url: \"https://sandbox-api.craftgate.io\",\n  api_key: \"\u003cYOUR SANDBOX API KEY\u003e\",\n  secret_key: \"\u003cYOUR SANDBOX SECRET KEY\u003e\"\n...\n```\n\n**config/prod.exs**\n```elixir\n...\nconfig :craftgate,\n  base_url: \"https://api.craftgate.io\",\n  api_key: System.get_env(\"CRAFTGATE__API_KEY\"),\n  secret_key: System.get_env(\"CRAFTGATE__SECRET_KEY\")\"\n...\n```\n\n### Non-Phoenix Apps or Manual Configuration\nIf you're not using Phoenix, or if you can't/don't want to use the `Config` module you can also configure Craftgate by injecting the same properties into the `:craftgate` key using `Application.put_env/3`\n\n```elixir\nApplication.put_env(:craftgate, :api_key, \"\u003cYOUR API KEY\u003e\")\nApplication.put_env(:craftgate, :secret_key, \"\u003cYOUR SECRET KEY\u003e\")\nApplication.put_env(:craftgate, :base_url, \"https://sandbox-api.craftgate.io\")\n```\n\n## Usage\nThe Craftgate Elixir client is stateless, so unlike its counterparts in other programming languages, you do not have to instantiate any Craftgate client. Instead, you can access specificy adapters directly, either through the adapter module itself, or through the convenience accessors on the `Craftgate` module itself.\n\nBelow is a list of all the adapters that are available:\n\n| Module | Accessor | Responsibilities |\n|--------|----------|------------------|\n| `Craftgate.Adapter.FileReportingAdapter` | `Craftgate.file_reporting/0` | File-based reporting activities like obtaining daily transaction reports |\n| `Craftgate.Adapter.FraudAdapter` | `Craftgate.fraud/0` | Fraud operations like retrieving potentially fraudulent transactions, marking them as safe, managing fraud values |\n| `Craftgate.Adapter.HookAdapter` | `Craftgate.hook/0` | Hook-related utility functions like verifying incoming webhooks |\n| `Craftgate.Adapter.InstallmentAdapter` | `Craftgate.installment/0` | Retrieving per-installment pricing information based on installment count or BIN number |\n| `Craftgate.Adapter.OnboardingAdapter` | `Craftgate.onboarding/0` | Conducting CRUD operations on buyers and submerchants |\n| `Craftgate.Adapter.PayByLinkAdapter` | `Craftgate.pay_by_link/0` | Managing and listing products available for the pay-by-link feature |\n| `Craftgate.Adapter.PaymentAdapter` | `Craftgate.payment/0` | Conducting payments, managing stored cards |\n| `Craftgate.Adapter.PaymentReportingAdapter` | `Craftgate.payment_reporting/0` | Searching payments, retrieving payment details, retrieving payment transaction records |\n| `Craftgate.Adapter.SettlementReportingAdapter` | `Craftgate.settlement_reporting/0` | Settlement operations like search payout completed transactions, search bounced payout transactions |\n| `Craftgate.Adapter.SettlementAdapter` | `Craftgate.settlement/0` | Settlement operations like create instant wallet settlement |\n| `Craftgate.Adapter.WalletAdapter` | `Craftgate.wallet/0` | Wallet operations like sending and receiving remittance, searching walletes and wallet transactions of members |\n\nOnce Craftgate is configured, you can use one of these adapters to interact with Craftgate API.\n\n```elixir\ndefmodule Orders do\n  def refund_order(order_id) do\n    with {:ok, order} \u003c- Order.get(order_id),\n         {:ok, refund_result} \u003c- Craftgate.Adapter.PaymentAdapter.refund_payment(%Craftgate.Request.RefundPaymentRequest{\n            payment_id: order.craftgate_payment_id,\n            refund_destination_type: Craftgate.Model.RefundDestinationType.card(),\n         }),\n         ...\n    do\n      ...\n    else\n      ...\n    end\n  end\nend\n```\n\n## Running Samples\nThis project has a set of samples that you can run to interact with the Craftgate API, located at [lib/mix/tasks/sample](https://github.com/ygunayer/craftgate-elixir/tree/main/lib/mix/tasks/sample/).\n\nThese samples are constructed as Mix tasks so you can even run them after adding `craftgate-elixir` as a dependency to your project.\n\n```bash\n$ mix sample.payment.create\n[lib/mix/tasks/sample/payment/create.ex:45: Mix.Tasks.Sample.Payment.Create.run/1]\nresult #=\u003e %Craftgate.Response.PaymentResponse{\n...\n}\n```\n\nNote that by default these samples use the public API keypairs found at [https://developer.craftgate.io](https://developer.craftgate.io) and target the sandbox environment of Craftgate API at [https://sandbox-api.craftgate.io](https://sandbox-api.craftgate.io), but they will also try to use any existing configuration you might have. As such, if you run these samples from your own project with Craftgate already configured, you will be access the Craftgate API with your own credentials.\n\nIn addition to the Mix tasks, you can also jump into a Mix-enabled interactive Elixir session, put your credentials into the `:api_key` and `:secret_key` keys of the `:craftgate` configuration and run any adapter method.\n\n```bash\n$ iex -S mix\n\niex(1)\u003e Application.put_env(:craftgate, :api_key, \"\u003cYOUR API KEY\u003e\")\n:ok\niex(2)\u003e Application.put_env(:craftgate, :secret_key, \"\u003cYOUR SECRET KEY\u003e\")\n:ok\niex(3)\u003e Application.put_env(:craftgate, :base_url, \"https://sandbox-api.craftgate.io\")\n:ok\niex(4)\u003e Craftgate.Adapter.PaymentReportingAdapter.retrieve_payment(1)\n{:ok,\n %Craftgate.Response.ReportingPaymentResponse{\n   retry_count: 0,\n   refundable_price: Decimal.new(\"100.0\"),\n   refund_status: :NOT_REFUNDED,\n   ...\n }\n}\n```\n\n## Contributing\nFor instructions on how to contribute to the project please see [CONTRIBUTING.md](./CONTRIBUTING.md)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fygunayer%2Fcraftgate-elixir-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fygunayer%2Fcraftgate-elixir-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fygunayer%2Fcraftgate-elixir-client/lists"}