{"id":20881983,"url":"https://github.com/5xruby/tappay-rails","last_synced_at":"2025-05-12T17:31:07.562Z","repository":{"id":72023226,"uuid":"95404731","full_name":"5xRuby/tappay-rails","owner":"5xRuby","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-25T04:14:00.000Z","size":73,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T08:44:54.218Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/5xRuby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-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}},"created_at":"2017-06-26T03:24:47.000Z","updated_at":"2021-08-09T03:33:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"479b22de-8e46-4956-a224-f6d6a88112a9","html_url":"https://github.com/5xRuby/tappay-rails","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5xRuby%2Ftappay-rails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5xRuby%2Ftappay-rails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5xRuby%2Ftappay-rails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/5xRuby%2Ftappay-rails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/5xRuby","download_url":"https://codeload.github.com/5xRuby/tappay-rails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253787227,"owners_count":21964296,"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-11-18T07:28:30.523Z","updated_at":"2025-05-12T17:31:07.526Z","avatar_url":"https://github.com/5xRuby.png","language":"Ruby","readme":"# tappay-rails\n\nAn API wrapper for [TapPay](https://www.tappaysdk.com).\n\n\n## Notice\n\nThis library is using TapPay API **v2**. See the v2 docs [here|https://onedrive.live.com/download?cid=2E7ABBDC6C509913\u0026resid=2E7ABBDC6C509913%215173\u0026authkey=AH5sDA8pWBPnQ0U]\n\nFor **v3** usage, please consider [tappay-ruby|https://github.com/hzchirs/tappay-ruby].\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tappay-rails', github: '5xRuby/tappay-rails'\n```\n\nAnd then execute:\n\n```bash\n$ bundle\n```\n\nFinally, run the install generator:\n\n```bash\n$ rails generate tap_pay:install\n```\n\nand setup the configurations in `config/initializers/tappay.rb`.\n\n### Installing Front-end Stuff\n\nYou'll need to `require tappay` in your JavaScript manifest. Place it after `require jquery` like this in `application.js`:\n\n```diff\n  //= require rails-ujs\n  //= require turbolinks\n  //= require jquery\n+ //= require tappay\n```\n\nIf you are not using jQuery in your project, you may need to require `tappay_with_zepto` instead because [jQuery.payment](https://github.com/stripe/jquery.payment) depends on a jQuery-like lib.\n\n```diff\n  //= require rails-ujs\n  //= require turbolinks\n+ //= require tappay_with_zepto\n```\n\n\n## Basic Usage\n\n### In The View\n\nPlace `tappay_card_input` in any form:\n\n```erb\n\u003c%= form_for @order do |f| %\u003e\n  \u003c%= tappay_card_input name: :credit_card %\u003e\n  \u003c%= f.submit %\u003e\n\u003c% end %\u003e\n```\n\nOr, if you are using [Simple Form 2.x](https://github.com/plataformatec/simple_form), add `as: :tappay_card` to any desired input:\n\n```slim\n= simple_form_for @credit_card do |f|\n  = f.input :data, as: :tappay_card\n  = f.submit\n```\n\n### Controller Side\n\nYou can create an `TapPay::Response::CardInfo` response object using the incoming params:\n\n```rb\ncard = TapPay::Response::CardInfo.new(params[:credit_card])\n\ncard.prime          # =\u003e \"1a836c4958c1525c7cf3b51bd90b1d3ad4e96dcc287867512f4d267ad4c1e794\"\ncard.lastfour       # =\u003e \"4242\"\ncard.funding.to_s   # =\u003e \"Credit Card\"\ncard.funding.to_sym # =\u003e :credit_card\ncard.funding == 0   # =\u003e true\ncard.type.to_s      # =\u003e \"VISA\"\ncard.type.to_sym    # =\u003e :visa\ncard.type.to_i      # =\u003e 1\n```\n\nOr to assign the data to any model, you can write a method to permit the params passed in:\n\n```rb\n  def credit_card_params\n    params.require(:credit_card).permit(data: [:prime, :bincode, :lastfour, :issuer, :funding, :type])\n  end\n```\n\n### Charge The User\n\nAfter you get the [prime](https://docs.tappaysdk.com/tutorial/zh/reference.html#prime) (`card.prime`), you can use it whihin 30 seconds to ...\n\n#### Make a one time charge\n\nFor example:\n\n```rb\n# All the shown arguments are required. For more info, see\n# https://docs.tappaysdk.com/tutorial/zh/back.html#pay-by-prime-api\nreq = TapPay::Request::PayByPrime.new(\n  prime: '977d9963e56edcc20b0c0b0351883f38666dc60f08d6fe0f3b6162f736b1ec5b',\n  amount: 100,\n  details: \"An apple and a pen.\",\n  ptradeid: \"TapPay_Test_001\",\n  cardholder: {\n    name: \"王小明\",\n    email: \"LittleMing@Wang.com\",\n    phonenumber: \"+886923456789\"\n  }\n)\n\nres = req.request\n\nres.success? # =\u003e true\nres.rectradeid # =\u003e \"D20170626vb5MyJ\" (this ID will be used for future refunding)\nres.orderid # =\u003e \"TP20170626vb5MyJ\"\nres.card_info.lastfour # =\u003e \"4242\"\n# For more info of the respond object, see\n# https://docs.tappaysdk.com/tutorial/zh/back.html#pay-by-prime-api\n```\n\n#### Get the card token (or also make a one time charge)\n\nSince the [prime](https://docs.tappaysdk.com/tutorial/zh/reference.html#prime) can only be used once, we can get a card token and save it for future charging, without asking the user for their credit card number again.\n\nTo do this, set `remember` to `true` when using the PayByPrime API like this:\n\n```diff\n  req = TapPay::Request::PayByPrime.new(\n    prime: '977d9963e56edcc20b0c0b0351883f38666dc60f08d6fe0f3b6162f736b1ec5b',\n    amount: 100,\n    details: \"An apple and a pen.\",\n    ptradeid: \"TapPay_Test_001\",\n    cardholder: {\n      name: \"王小明\",\n      email: \"LittleMing@Wang.com\",\n      phonenumber: \"+886923456789\"\n    },\n+   remember: true\n  )\n```\n\nThen, you can get the card token with the response:\n\n```\nres = req.request\n\nres.success? # =\u003e true\nres.card_secret.key # =\u003e \"2ddb643f375dca31323c79e031ab6b5efbcdfa0294863642afbd9f3be87e032c\"\nres.card_secret.token # =\u003e \"977d9963e56edcc20b0c0b0351883f38666dc60f08d6fe0f3b6162f736b1ec5b\"\n```\n\n... and use them in the future like this:\n\n```rb\n# All the shown arguments are required. For more info, see\n# https://docs.tappaysdk.com/tutorial/zh/back.html#pay-by-card-token-api\nreq = TapPay::Request::PayByCardToken.new(\n  cardkey: '2ddb643f375dca31323c79e031ab6b5efbcdfa0294863642afbd9f3be87e032c',\n  cardtoken: '977d9963e56edcc20b0c0b0351883f38666dc60f08d6fe0f3b6162f736b1ec5b',\n  amount: 100,\n  details: \"An apple and a pen.\",\n  ptradeid: \"TapPay_Test_001\"\n)\n\nres = req.request\nres.success? # =\u003e true\n# For more info of the respond object, see\n# https://docs.tappaysdk.com/tutorial/zh/back.html#pay-by-card-token-api\n```\n\n\u003e TODO: Instructions for not charging the user but only get a card token, or also checking the card balance.\n\n\n## TODO\n\n- Wrap Refund API.\n- Wrap Cap Today API.\n- Wrap Record API.\n- Write tests.\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5xruby%2Ftappay-rails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F5xruby%2Ftappay-rails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F5xruby%2Ftappay-rails/lists"}