HyperPay 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.idea/.gitignore +8 -0
- data/.idea/hyperpay.iml +83 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/HyperPay.gemspec +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +107 -0
- data/Rakefile +12 -0
- data/lib/HyperPay/base.rb +70 -0
- data/lib/HyperPay/configuration.rb +9 -0
- data/lib/HyperPay/copy_and_pay.rb +74 -0
- data/lib/HyperPay/payment_parameter_builder.rb +24 -0
- data/lib/HyperPay/version.rb +5 -0
- data/lib/hyper_pay.rb +19 -0
- data/sig/HyperPay.rbs +4 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb8d58ae8360368a30935be12cc4e3dc0d2c5a234b6d1d31cad4959428864b3e
|
4
|
+
data.tar.gz: dfa14a6b30908707bc19eff2e4165b86bb42cc349ec50e32e659ec4fdeb2a5ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd532c6e1f74bbd756f0f544871edf1b3096a2395a50c62781848cfce90fdd62f3bac08ff1d95d0f310889f3432a434140b9337e2e419f1d8589f5e527478626
|
7
|
+
data.tar.gz: 279b7866cf4eae7488f5f574366621bc274e3f60aaef460512a6f8ff299433725e1a8a19fd6295f9be26dcce1ae922f2369bdea755822fb5e5ea4fbede1e111c
|
data/.idea/.gitignore
ADDED
data/.idea/hyperpay.iml
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="jdk" jdkName="rbenv: 3.2.2" jdkType="RUBY_SDK" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.2.2) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.5.6, rbenv: 3.2.2) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="httparty (v0.21.0, rbenv: 3.2.2) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.7.1, rbenv: 3.2.2) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, rbenv: 3.2.2) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.1.5, rbenv: 3.2.2) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.22.2, rbenv: 3.2.2) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="multi_xml (v0.6.0, rbenv: 3.2.2) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.24.0, rbenv: 3.2.2) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.3.0.5, rbenv: 3.2.2) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.7.3, rbenv: 3.2.2) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.2.2) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.1.0, rbenv: 3.2.2) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.9.0, rbenv: 3.2.2) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.6, rbenv: 3.2.2) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.61.0, rbenv: 3.2.2) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.31.1, rbenv: 3.2.2) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.2.2) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.5.0, rbenv: 3.2.2) [gem]" level="application" />
|
33
|
+
</component>
|
34
|
+
<component name="RakeTasksCache">
|
35
|
+
<option name="myRootTask">
|
36
|
+
<RakeTaskImpl id="rake">
|
37
|
+
<subtasks>
|
38
|
+
<RakeTaskImpl description="Build HyperPay-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
39
|
+
<RakeTaskImpl id="build">
|
40
|
+
<subtasks>
|
41
|
+
<RakeTaskImpl description="Generate SHA512 checksum if HyperPay-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
42
|
+
</subtasks>
|
43
|
+
</RakeTaskImpl>
|
44
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
45
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
46
|
+
<RakeTaskImpl description="Build and install HyperPay-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
47
|
+
<RakeTaskImpl id="install">
|
48
|
+
<subtasks>
|
49
|
+
<RakeTaskImpl description="Build and install HyperPay-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
50
|
+
</subtasks>
|
51
|
+
</RakeTaskImpl>
|
52
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push HyperPay-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
53
|
+
<RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
|
54
|
+
<RakeTaskImpl id="rubocop">
|
55
|
+
<subtasks>
|
56
|
+
<RakeTaskImpl description="Autocorrect RuboCop offenses (only when it's safe)" fullCommand="rubocop:autocorrect" id="autocorrect" />
|
57
|
+
<RakeTaskImpl description="Autocorrect RuboCop offenses (safe and unsafe)" fullCommand="rubocop:autocorrect_all" id="autocorrect_all" />
|
58
|
+
<RakeTaskImpl description="" fullCommand="rubocop:auto_correct" id="auto_correct" />
|
59
|
+
</subtasks>
|
60
|
+
</RakeTaskImpl>
|
61
|
+
<RakeTaskImpl description="Run the test suite" fullCommand="test" id="test" />
|
62
|
+
<RakeTaskImpl id="test">
|
63
|
+
<subtasks>
|
64
|
+
<RakeTaskImpl description="Print out the test command" fullCommand="test:cmd" id="cmd" />
|
65
|
+
<RakeTaskImpl description="Show which test files fail when run in isolation" fullCommand="test:isolated" id="isolated" />
|
66
|
+
<RakeTaskImpl description="Show bottom 25 tests wrt time" fullCommand="test:slow" id="slow" />
|
67
|
+
<RakeTaskImpl description="" fullCommand="test:deps" id="deps" />
|
68
|
+
</subtasks>
|
69
|
+
</RakeTaskImpl>
|
70
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
71
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
72
|
+
<RakeTaskImpl id="release">
|
73
|
+
<subtasks>
|
74
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
75
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
76
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
77
|
+
</subtasks>
|
78
|
+
</RakeTaskImpl>
|
79
|
+
</subtasks>
|
80
|
+
</RakeTaskImpl>
|
81
|
+
</option>
|
82
|
+
</component>
|
83
|
+
</module>
|
data/.idea/modules.xml
ADDED
data/.idea/vcs.xml
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at m@kaakati.me. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/HyperPay.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/HyperPay/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "HyperPay"
|
7
|
+
spec.version = HyperPay::VERSION
|
8
|
+
spec.authors = ["Mohamad Kaakati"]
|
9
|
+
spec.email = ["m@kaakati.me"]
|
10
|
+
|
11
|
+
spec.summary = "A wrapper around HyperPay Copy And Pay API."
|
12
|
+
spec.description = "HyperPay is a wrapper around HyperPay Copy And Pay API. It provides a simple way to integrate with HyperPay's MENA payment gateway."
|
13
|
+
spec.homepage = "https://kaakati.me/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/kaakati/hyperpay_ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/kaakati/hyperpay_ruby/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = %w[lib README.md]
|
34
|
+
|
35
|
+
# Uncomment to register a new dependency of your gem
|
36
|
+
spec.add_dependency "httparty"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, check out our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Mohamad Kaakati
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
|
2
|
+
# HyperPay Gem
|
3
|
+
|
4
|
+
HyperPay is a powerful payment gateway, transforming the online buying experience in the MENA region. HyperPay enable internet businesses to accept and manage payments online, with more flexibility, security and ease.
|
5
|
+
|
6
|
+
HyperPay have been processing online payments since 2014. Today, HyperPay go beyond the payment gateway, as we provide merchants across almost every industry, a full-suite of online payment solutions, to serve every need.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'HyperPay'
|
13
|
+
```
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
`config/initializers/hyperpay.rb`
|
18
|
+
```ruby
|
19
|
+
HyperPay.configure do |config|
|
20
|
+
config.authorization = "HYPER_PAY_AUTH_TOKEN"
|
21
|
+
config.environment = :sandbox
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
# Usage example
|
26
|
+
|
27
|
+
### Generate Checkout ID
|
28
|
+
```ruby
|
29
|
+
# Generate HyperPay Checkout ID
|
30
|
+
#
|
31
|
+
# Parameters:
|
32
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
33
|
+
# @return [Hash] {"result"=>{"code"=>"000.200.100", "description"=>"successfully created checkout"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:22+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03", "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
34
|
+
|
35
|
+
checkout = HyperPay::CopyAndPay.new.create_checkout_id do |params|
|
36
|
+
params.add "entityId", "HYPER_PAY_ENTITY_ID"
|
37
|
+
params.add "customer.email", "john@doe.com"
|
38
|
+
params.add "customer.mobile", "9665xxxxxxxx"
|
39
|
+
params.add "customer.givenName", "John"
|
40
|
+
params.add "customer.surname", "Doe"
|
41
|
+
params.add "billing.street1", "STREET_NAME"
|
42
|
+
params.add "billing.country", "SA"
|
43
|
+
params.add "billing.city", "Riyadh"
|
44
|
+
params.add "billing.state", ""
|
45
|
+
params.add "billing.postcode", "00000"
|
46
|
+
params.add "customParameters[3DS2_enrolled]", "true"
|
47
|
+
params.add "merchantTransactionId", "YOUR_INVOICE_NUMBER"
|
48
|
+
params.add "paymentType", "DB"
|
49
|
+
params.add "currency", "SAR"
|
50
|
+
params.add "amount", "100" # On Sandbox, HyperPay Can process non-decimal numbers only.
|
51
|
+
end
|
52
|
+
|
53
|
+
p checkout['id']
|
54
|
+
p checkout['result']['code']
|
55
|
+
p checkout['result']['description']
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
### Response
|
60
|
+
```ruby
|
61
|
+
{"result"=>{"code"=>"000.200.100", "description"=>"successfully created checkout"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:22+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03", "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
62
|
+
```
|
63
|
+
|
64
|
+
### Get Payment Status for Checkout ID
|
65
|
+
```ruby
|
66
|
+
# Get HyperPay payment status for a given checkout
|
67
|
+
#
|
68
|
+
# Parameters:
|
69
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
70
|
+
# @checkout_id HyperPay Checkout ID
|
71
|
+
# @return [Hash] {"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
72
|
+
def get_status(entity_id:, checkout_id:)
|
73
|
+
get("/v1/checkouts/#{checkout_id}/payment"+"?entityId=#{entity_id}")
|
74
|
+
end
|
75
|
+
|
76
|
+
checkout = HyperPay::CopyAndPay.new.get_status(entity_id: "", checkout_id: "")
|
77
|
+
p checkout['id']
|
78
|
+
p checkout['result']['code']
|
79
|
+
p checkout['result']['description']
|
80
|
+
```
|
81
|
+
|
82
|
+
### Response
|
83
|
+
```ruby
|
84
|
+
{"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
85
|
+
```
|
86
|
+
|
87
|
+
## Backoffce Operations
|
88
|
+
|
89
|
+
### Capture Payment
|
90
|
+
```ruby
|
91
|
+
HyperPay::CopyAndPay.new.capture_payment(entity_id:, checkout_id:, amount:, currency:)
|
92
|
+
```
|
93
|
+
|
94
|
+
### Refund Payment
|
95
|
+
```ruby
|
96
|
+
HyperPay::CopyAndPay.new.refund_payment(entity_id: "", checkout_id: "", amount: "", currency: "")
|
97
|
+
```
|
98
|
+
|
99
|
+
### Reverse a payment
|
100
|
+
```ruby
|
101
|
+
HyperPay::CopyAndPay.new.reverse_payment(entity_id: "", checkout_id: "")
|
102
|
+
```
|
103
|
+
|
104
|
+
|
105
|
+
## Authors
|
106
|
+
|
107
|
+
- [Mohamad Kaakati (@kaakati)](https://www.github.com/kaakati)
|
data/Rakefile
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
require "HyperPay/configuration"
|
5
|
+
|
6
|
+
module HyperPay
|
7
|
+
class Base
|
8
|
+
include HTTParty
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.class.base_uri base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def get(path)
|
17
|
+
request(:get, path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path, payload = {})
|
21
|
+
encoded_payload = URI.encode_www_form(payload)
|
22
|
+
request(:post, path, body: encoded_payload, headers: { "Content-Type" => "application/x-www-form-urlencoded" })
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(path, payload = {})
|
26
|
+
request(:put, path, payload)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(path)
|
30
|
+
request(:delete, path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def request(method, path, options = {})
|
34
|
+
prepare_headers(options)
|
35
|
+
prepare_body(options)
|
36
|
+
response = self.class.send(method, path, options)
|
37
|
+
JSON.parse(response.body)
|
38
|
+
rescue HTTParty::Error, StandardError => e
|
39
|
+
{ error: e.message }
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def parse_response(response)
|
44
|
+
JSON.parse(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def base_url
|
48
|
+
HyperPay.configuration.environment == :sandbox ? "https://eu-test.oppwa.com" : "https://eu-prod.oppwa.com"
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def prepare_headers(options)
|
54
|
+
content_type = options.dig(:headers, "Content-Type") == "application/x-www-form-urlencoded" ?
|
55
|
+
"application/x-www-form-urlencoded" : "application/json"
|
56
|
+
default_headers = {
|
57
|
+
"Authorization" => "Bearer #{HyperPay.configuration.authorization}",
|
58
|
+
"Accept" => "application/json",
|
59
|
+
"Content-Type" => content_type
|
60
|
+
}
|
61
|
+
options[:headers] = default_headers.merge(options[:headers] || {})
|
62
|
+
end
|
63
|
+
|
64
|
+
def prepare_body(options)
|
65
|
+
if options[:body] && options[:headers]["Content-Type"] == "application/json"
|
66
|
+
options[:body] = options[:body].to_json unless options[:body].is_a?(String)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "HyperPay/payment_parameter_builder"
|
4
|
+
require "HyperPay/base"
|
5
|
+
|
6
|
+
module HyperPay
|
7
|
+
class CopyAndPay < HyperPay::Base
|
8
|
+
# Generate HyperPay Checkout ID
|
9
|
+
#
|
10
|
+
# Parameters:
|
11
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
12
|
+
# @return [Hash] {"result"=>{"code"=>"000.200.100", "description"=>"successfully created checkout"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:22+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03", "id"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
13
|
+
def create_checkout_id(&block)
|
14
|
+
builder = PaymentParameterBuilder.new
|
15
|
+
yield(builder) if block_given?
|
16
|
+
builder.validate! # Perform validations
|
17
|
+
post("/v1/checkouts", builder.parameters)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get HyperPay payment status for a given checkout
|
21
|
+
#
|
22
|
+
# Parameters:
|
23
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
24
|
+
# @checkout_id HyperPay Checkout ID
|
25
|
+
# @return [Hash] {"result"=>{"code"=>"000.200.000", "description"=>"transaction pending"}, "buildNumber"=>"a58fee65f51ad5776b3c44e9929ca39a62a7cb43@2024-03-04 12:55:38 +0000", "timestamp"=>"2024-03-05 13:50:29+0000", "ndc"=>"ABCE449B5FC84ED5A1C7174840C7A3F8.uat01-vm-tx03"}
|
26
|
+
def get_status(entity_id:, checkout_id:)
|
27
|
+
get("/v1/checkouts/#{checkout_id}/payment"+"?entityId=#{entity_id}")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Capture an authorization
|
31
|
+
# A capture is used to request clearing for previously authorized funds.
|
32
|
+
# Captures can be for full or partial amounts and multiple capture requests against the same PA are allowed.
|
33
|
+
#
|
34
|
+
# Parameters:
|
35
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
36
|
+
# @checkout_id HyperPay Checkout ID
|
37
|
+
# @amount Amount
|
38
|
+
# @currency Currency
|
39
|
+
def capture_payment(entity_id:, checkout_id:, amount:, currency:)
|
40
|
+
post("/v1/payments/#{checkout_id}", { entityId: entity_id, paymentType: "CP", currency: currency, amount: amount })
|
41
|
+
end
|
42
|
+
|
43
|
+
# Refund a payment
|
44
|
+
# A refund is performed against a previous payment, referencing its `payment.id` by
|
45
|
+
# sending a POST request over HTTPS to the /payments/{id} endpoint.
|
46
|
+
# A refund can be performed against debit (DB) or captured pre-authorization (PA->CP) payment types.
|
47
|
+
# Where supported, the amount field can be used to process a partial or full amount.
|
48
|
+
#
|
49
|
+
# Parameters:
|
50
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
51
|
+
# @checkout_id HyperPay Checkout ID
|
52
|
+
# @amount Amount
|
53
|
+
# @currency Currency
|
54
|
+
def refund_payment(entity_id:, checkout_id:, amount:, currency:)
|
55
|
+
post("/v1/payments/#{checkout_id}", { entityId: entity_id, amount: amount, currency: currency, paymentType: "RF" })
|
56
|
+
end
|
57
|
+
|
58
|
+
# Reverse a payment
|
59
|
+
# A reversal is performed against a previous payment, referencing its payment.id
|
60
|
+
# by sending a POST request over HTTPS to the /payments/{id} endpoint.
|
61
|
+
# A reversal should be sent against pre-authorization (PA) payment type.
|
62
|
+
# When reversing a card payment and if sent within the time-frame the authorization is not captured yet,
|
63
|
+
# the reversal causes an authorization reversal request to be sent to the card issuer
|
64
|
+
# to clear the funds held against the authorization.
|
65
|
+
#
|
66
|
+
# Parameters:
|
67
|
+
# @entity_id Entity ID that was used to generate the Checkout ID
|
68
|
+
# @checkout_id HyperPay Checkout ID
|
69
|
+
def reverse_payment(entity_id:, checkout_id:)
|
70
|
+
post("/v1/payments/#{checkout_id}", { entityId: entity_id, paymentType: "RV" })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module HyperPay
|
2
|
+
class PaymentParameterBuilder
|
3
|
+
REQUIRED_PARAMETERS = %w[entityId customer.email customer.mobile customer.givenName customer.surname billing.street1 billing.city billing.state billing.country billing.postcode customParameters[3DS2_enrolled] merchantTransactionId paymentType currency amount].freeze
|
4
|
+
|
5
|
+
attr_reader :parameters
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@parameters = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Implementation of `add` method returns `self` to allow chaining
|
12
|
+
def add(key, value)
|
13
|
+
@parameters[key] = value
|
14
|
+
self # Return self to allow chaining
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate!
|
18
|
+
missing_params = REQUIRED_PARAMETERS - @parameters.keys
|
19
|
+
unless missing_params.empty?
|
20
|
+
raise ArgumentError, "Missing required parameters: #{missing_params.join(', ')}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hyper_pay.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "HyperPay/version"
|
4
|
+
require_relative "HyperPay/configuration"
|
5
|
+
require_relative "HyperPay/copy_and_pay"
|
6
|
+
|
7
|
+
module HyperPay
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
|
13
|
+
def configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/sig/HyperPay.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: HyperPay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mohamad Kaakati
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: HyperPay is a wrapper around HyperPay Copy And Pay API. It provides a
|
28
|
+
simple way to integrate with HyperPay's MENA payment gateway.
|
29
|
+
email:
|
30
|
+
- m@kaakati.me
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".idea/.gitignore"
|
36
|
+
- ".idea/hyperpay.iml"
|
37
|
+
- ".idea/modules.xml"
|
38
|
+
- ".idea/vcs.xml"
|
39
|
+
- ".rubocop.yml"
|
40
|
+
- CHANGELOG.md
|
41
|
+
- CODE_OF_CONDUCT.md
|
42
|
+
- HyperPay.gemspec
|
43
|
+
- LICENSE.txt
|
44
|
+
- README.md
|
45
|
+
- Rakefile
|
46
|
+
- lib/HyperPay/base.rb
|
47
|
+
- lib/HyperPay/configuration.rb
|
48
|
+
- lib/HyperPay/copy_and_pay.rb
|
49
|
+
- lib/HyperPay/payment_parameter_builder.rb
|
50
|
+
- lib/HyperPay/version.rb
|
51
|
+
- lib/hyper_pay.rb
|
52
|
+
- sig/HyperPay.rbs
|
53
|
+
homepage: https://kaakati.me/
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata:
|
57
|
+
homepage_uri: https://kaakati.me/
|
58
|
+
source_code_uri: https://github.com/kaakati/hyperpay_ruby
|
59
|
+
changelog_uri: https://github.com/kaakati/hyperpay_ruby/CHANGELOG.md
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
- README.md
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.5.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: A wrapper around HyperPay Copy And Pay API.
|
80
|
+
test_files: []
|