{"id":13778750,"url":"https://github.com/leafo/lua-payments","last_synced_at":"2025-11-14T16:06:10.688Z","repository":{"id":12289683,"uuid":"14916862","full_name":"leafo/lua-payments","owner":"leafo","description":"Various payment provider APIs for Lua (and OpenResty): Stripe, PayPal","archived":false,"fork":false,"pushed_at":"2022-03-30T21:12:51.000Z","size":167,"stargazers_count":73,"open_issues_count":1,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-04T17:28:58.800Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"MoonScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-04T07:09:44.000Z","updated_at":"2024-11-20T03:16:11.000Z","dependencies_parsed_at":"2022-08-21T06:10:46.056Z","dependency_job_id":null,"html_url":"https://github.com/leafo/lua-payments","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-payments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-payments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-payments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Flua-payments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/lua-payments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240286520,"owners_count":19777353,"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","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":[],"created_at":"2024-08-03T18:00:57.130Z","updated_at":"2025-11-14T16:06:05.667Z","avatar_url":"https://github.com/leafo.png","language":"MoonScript","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# Lua Payments\n\n![test](https://github.com/leafo/lua-payments/workflows/test/badge.svg)\n\nBindings to various payment provider APIs for use in Lua (with OpenResty via\nLapis or anything that supports LuaSocket or\n[cqueues](http://www.25thandclement.com/~william/projects/cqueues.html) with\n[lua-http](https://github.com/daurnimator/lua-http))\n\nThe following APIs are supported:\n\n* [Stripe](#stripe)\n* [PayPal Express Checkout](#paypal-express-checkout)\n* [PayPal REST](#paypal-rest-api)\n* [PayPal Adaptive Payments](#paypal-adaptive-payments)\n\n## Install\n\n    luarocks install payments\n\n## Examples\n\n\n### PayPal Rest API\n\nCreate the API client:\n\n```lua\nlocal paypal = require(\"payments.paypal\")\n\nlocal client = paypal.PayPalRest({\n  sandbox = true,\n  client_id = \"AVP_0123445\",\n  secret = \"EFAAAAEFE-HELLO-WORLD\",\n})\n```\n\nFetch some data:\n\n```lua\nlocal payments = client:payment_resources()\n```\n\nCreate a new payment:\n\n\n```lua\nlocal res, status = client:create_payment({\n  intent = \"sale\",\n  payer = {\n    payment_method: \"paypal\"\n  },\n  transactions = {\n    {\n      description = \"My thinger\",\n      invoice_number = \"P-1291829281\",\n\n      amount = {\n        total = \"5.99\"\n        currency = \"USD\"\n      }\n    }\n  },\n  redirect_urls = {\n    return_url = \"http://example.com/confirm-payment\",\n    cancel_url = \"http://example.com/cancel-payment\"\n  }\n})\n```\n\n\n**Note:** This currently uses the PayPal V1 REST API. You can force calls to go\nto V2 by adjusting the following field on your client instance:\n\n```lua\nclient.api_version = \"v2\"\nclient:create_checkout_order({...})\n```\n\n\n### Stripe\n\nCreate the API client:\n\n```lua\n\nlocal Stripe = require(\"payments.stripe\").Stripe\n\nlocal client = Stripe({\n  client_id = \"ca_12345\",\n  client_secret = \"sk_test_helloworld\",\n  publishable_key = \"pk_test_blahblahblahb\"\n})\n```\n\nFetch some data:\n\n```lua\n\n-- each resource exposed by Stripe API has a respective list_, get_, and each_\n-- method in this library:\n\nlocal result = client:list_charges()\nlocal result = client:list_accounts({ limit = \"100 \"})\nlocal result = client:list_disputes({ starting_after = \"dsp_12343\" })\n\n-- get a single item\nlocal result = client:get_customer(\"cust_12o323480\")\n\n-- iterate through every refund, fetching each page as needed\nfor refund in client:each_refund() do\n  print(refund.id)\nend\n```\n\nCreate a charge:\n\n```lua\nlocal result, err = client:charge({\n  card = \"tok_232u302\"\n  amount = \"5.99\",\n  currency = \"USD\",\n  description = \"indie games\"\n})\n```\n\nResouces can be created, updated, and deleted:\n\n```lua\n\nlocal customer = client:create_customer({\n  email = \"loaf@itch.zone\"\n})\n\nclient:update_customer(customer.id, {\n  account_balance = 23023\n})\n\nclient:delete_customer(customer.id)\n\n```\n\n### PayPal Express Checkout\n\nCreate the API client:\n\n```lua\nlocal paypal = require(\"payments.paypal\")\n\nlocal client = paypal.PayPalExpressCheckout({\n  sandbox = true,\n  auth = {\n    USER = \"me_1212121.leafo.net\",\n    PWD = \"123456789\",\n    SIGNATURE = \"AABBBC_CCZZZXXX\"\n  }\n})\n```\n\nCreate a new purchase page:\n\n```lua\nlocal res = assert(client:set_express_checkout({\n  returnurl = \"http://leafo.net/success\",\n  cancelurl = \"http://leafo.net/cancel\",\n  brandname = \"Purchase something\",\n  paymentrequest_0_amt = \"$5.99\"\n}))\n\n\n-- redirect the buyer to the payment page:\nprint(client:checkout_url(res.TOKEN))\n```\n\n\n### PayPal Adaptive Payments\n\n\u003e **Note:** This is a legacy API now deprecated by PayPal. You probably don't want to be using this.\n\nCreate the API client:\n\n```lua\nlocal paypal = require(\"payments.paypal\")\n\nlocal client = paypal.PayPalAdaptive({\n  sandbox = true,\n  application_id = \"APP-1234HELLOWORLD\",\n  auth = {\n    USER = \"me_1212121.leafo.net\",\n    PWD = \"123456789\",\n    SIGNATURE = \"AABBBC_CCZZZXXX\"\n  }\n})\n```\n\nCreate a new purchase page:\n\n\n```lua\nlocal res = assert(client:pay({\n  cancelUrl = \"http://leafo.net/cancel\",\n  returnUrl = \"http://leafo.net/return\",\n  currencyCode = \"EUR\",\n  receivers = {\n    {\n      email = \"me@example.com\",\n      amount = \"5.50\",\n      primary = true,\n    },\n    {\n      email = \"you@example.com\",\n      amount = \"1.50\",\n    }\n  }\n}))\n\n-- configure the checkout page\nassert(client:set_payment_options(res.payKey, {\n  [\"displayOptions.businessName\"] = \"My adaptive store front\"\n}))\n\n-- redirect the buyer to the payment page:\nprint(client:checkout_url(res.payKey))\n\n-- after completion, you can check the payment status\nlocal details = assert(client:payment_details(res.payKey))\n\n```\n\n\n## HTTP Client\n\nAll of the APIs exposed here are powered by HTTP. This client supports using\ndifferent HTTP client libraries depending on the environment.\n\nIf `ngx` is available in the global scope then Lapis' HTTP library is used by\ndefault.  This will give you non-blocking requests within nginx. Otherwise,\nLuaSec and LuaSocket are used.\n\nYou can manually set the client by passing a `http_provider` parameter to any\nof the client constructors. For example, to use cqueues pass\n`\"http.compat.socket\"` as the provider:\n\n```lua\nlocal Stripe = require(\"payments.stripe\").Stripe\n\nlocal client = Stripe({\n  http_provider = \"http.compat.socket\",\n  -- ...\n})\n```\n\n## License\n\nMIT, Copyright (C) 2022 by Leaf Corcoran\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Flua-payments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Flua-payments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Flua-payments/lists"}