koduc_express_paypal 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +130 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/koduc_express_paypal.gemspec +38 -0
- data/lib/koduc_exception_handling/koduc_api_errors.rb +25 -0
- data/lib/koduc_express_paypal/koduc_check_environment.rb +41 -0
- data/lib/koduc_express_paypal/koduc_request.rb +144 -0
- data/lib/koduc_express_paypal/koduc_response.rb +15 -0
- data/lib/koduc_express_paypal/koduc_validation.rb +195 -0
- data/lib/koduc_express_paypal/version.rb +7 -0
- data/lib/koduc_express_paypal.rb +37 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTU0OTkwZTZjZWVhMGIzN2JmMWMyNDllZjM5OWFhODAyNDY2NjM2Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWVjY2VhOTI1MDE1MzMzN2UzOGY4MjI3YTU2YWMxNjI3ZTg3ZGZlMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDUzNWI4MzZiZjg4YTM0MWI2NjU4ZjZiNGFjOGZhM2FmMzFkN2Y3MzA2Nzkx
|
10
|
+
ZDJhNWEzYWIzYzdjMzc4OWVjYWI0ZWJkNzNlZjc4ZDIzYzFhMmRiOThjZjQ1
|
11
|
+
ZjNlMGQyZGQ0MWQ2MTNkZmRlOTI0ZGJiN2NjOGNlYTBjN2JhZDY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2QxZjM3ZGEwYjQ2YTRjZjU0MGUwZTY4MjVjM2Q3ZGI5NzE4ZTk1ZTA1NTBi
|
14
|
+
OWUxMTNiYTUyYTRhZTFmZWMxZTcyZjMyM2JjNGU4M2I1YTQyMDVkZjAxMDNh
|
15
|
+
YzljNmMxNzA4ODllZTAyZTA3MzUyODg1OGE3YTE0ZjAyNmM3OTE=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers 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. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Akanksha01
|
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,130 @@
|
|
1
|
+
# KoducExpressPaypal
|
2
|
+
|
3
|
+
KoducExpressPaypal is a simple gem used for fulfilling the requirement of one time Paypal Express Checkout integration using NVP(Name Value Pair). The chief principle of designing this library is the involvement of different internal Express Checkout Paypal APIs.
|
4
|
+
|
5
|
+
It is developed for the usage in Ruby on Rails web applications and integrates as a Rails plugin.
|
6
|
+
|
7
|
+
It is developed in November 2015 by [KSolves](http://ksolves.com/) team with the help of valuable contributors.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
### From Git
|
12
|
+
|
13
|
+
Check out the latest source from git using:
|
14
|
+
|
15
|
+
git clone https://github.com/kartiksolves/koduc-paypal-express.git
|
16
|
+
|
17
|
+
if you're using Bundler, just add the following to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'koduc_express_paypal'
|
21
|
+
```
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install koduc_express_paypal
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
This simple example demonstrates how a purchase can be made using the KoducExpressPaypal gem.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'koduc_express_paypal'
|
36
|
+
|
37
|
+
# Declare the following paypal credentials in the same format in the environment files present in the config folder. Use development.rb for sandbox credentials and production.rb for live credentials. Write everything is string.
|
38
|
+
|
39
|
+
config.paypal_credentials = {
|
40
|
+
:USER => <userid>,
|
41
|
+
:PWD => <password>,
|
42
|
+
:SIGNATURE => <signature>
|
43
|
+
}
|
44
|
+
|
45
|
+
# Set the environment in the format given below.
|
46
|
+
# Default it will be a sandbox mode.
|
47
|
+
|
48
|
+
# For Sandbox mode use
|
49
|
+
KsCheckEnvironment::ks_sandbox(true)
|
50
|
+
|
51
|
+
# For Live mode use
|
52
|
+
KsCheckEnvironment::ks_sandbox(false)
|
53
|
+
|
54
|
+
# Form a hash of the required parameters in the format given below.
|
55
|
+
# All the fields are mandatory
|
56
|
+
# payment_amount => payment amount (Integers and float values are allowed else it will throw error message )
|
57
|
+
# payment_action => type of transaction (Only alphabets are allowed.)
|
58
|
+
# payment_currency => payment currency code (Only alphabets are allowed in capital letters.)
|
59
|
+
# cancel_url => redirect URL for use if the customer does not authorize payment
|
60
|
+
# return_url => redirect URL for use if the customer authorizes payment
|
61
|
+
# Pass the parameters in string
|
62
|
+
|
63
|
+
hash = {:payment_amount =><paymentAmount>,:payment_action=><paymentAction>,:payment_currency=><paymentCurrency>,:cancel_url=><cancelURL>,:return_url=><returnURL>}
|
64
|
+
|
65
|
+
# Form an object using the above hash
|
66
|
+
|
67
|
+
obj = KsExpressPaypal::KsRequest.new(hash)
|
68
|
+
|
69
|
+
# Check if the passed parameters are valid using the object formed above
|
70
|
+
|
71
|
+
validity = obj.valid?
|
72
|
+
|
73
|
+
# The format of the response obtained is {success: true/false ,response:[Error Array]}
|
74
|
+
# The value of success is true is the parameters are verified completely else it will be false.
|
75
|
+
# The value of response will be an Array consisting of the error messages in case the validation of the parameters failed. In case the value of success is true the response will be an empty array.
|
76
|
+
|
77
|
+
# If the success is true call the following method with the same object formed above
|
78
|
+
|
79
|
+
set_checkout = obj.ks_set_express_checkout
|
80
|
+
|
81
|
+
# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
|
82
|
+
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]}
|
83
|
+
# If the above call is successful the response will contain the TOKEN.
|
84
|
+
# If the above call is a failure refer the paypal errors.
|
85
|
+
|
86
|
+
# In case of success, using the token valued returned from above, redirect the customer to PayPal so they can approve the transaction:
|
87
|
+
|
88
|
+
# For sandbox
|
89
|
+
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<tokenValue>
|
90
|
+
|
91
|
+
# For LIVE redirect the customer to
|
92
|
+
https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=<tokenValue>
|
93
|
+
|
94
|
+
# The redirect presents the customer with a PayPal log-in page. After the customer logs in, PayPal displays the transaction details on the Payments Review page. The customer approves the payment on this page by clicking Continue.
|
95
|
+
|
96
|
+
# If the customer approves the payment, PayPal directs the customer to the payment confirmation page (the return URL specified above in the parameters described above). If the customer doesn't authorize the payment, PayPal directs the customer to the cancel URL that you also specified in the parameters described above, and you can attempt to re-initiate the checkout.
|
97
|
+
|
98
|
+
# If the customer approves the payment, find the checkout details using the following method by passing the TOKEN obtained above with the same object.
|
99
|
+
# It is advisable to display the details on the payment confirmation page using the below method
|
100
|
+
|
101
|
+
checkout_details = KsExpressPaypal::KsRequest.ks_checkout_details(<tokenValue>)
|
102
|
+
|
103
|
+
# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
|
104
|
+
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]}
|
105
|
+
# If the above call is successful the response will contain the TOKEN and the various other details with the PAYERID if the customer has verified the payment. Utilise the details obtained above accordingly.
|
106
|
+
# If the above call is a failure refer the paypal errors.
|
107
|
+
|
108
|
+
# In addition to the transaction details, your payment confirmation page should include a Confirm button. When the customer confirms the payment, call the below method to capture (collect) the payment. The following sample shows how to specify the PayerID and token value returned from the previous call. Provide the Payment Action with token and payerId:
|
109
|
+
|
110
|
+
do_checkout = KsExpressPaypal::KsRequest.ks_do_checkout(<tokenValue>,<paymentAction>,<payerId>)
|
111
|
+
|
112
|
+
# When PayPal processes the above call, it captures the payment by transferring the funds from the customer account to the appropriate merchant account and sends a confirmation e-mail to the customer.
|
113
|
+
|
114
|
+
# The format of the response in case of success is {success: true ,response:[Response returned from Paypal]}
|
115
|
+
# The format of the response in case of failure is {success: false ,response:[Error Message returned from Paypal]}
|
116
|
+
# Refer the paypal errors in case of failure.
|
117
|
+
```
|
118
|
+
## Queries and Issues
|
119
|
+
|
120
|
+
Your valuable queries and suggestions are welcomed. Please report the issues on GitHub at https://github.com/kartiksolves/koduc-paypal-express
|
121
|
+
|
122
|
+
## Contact
|
123
|
+
|
124
|
+
If you have any query, need support or advice just DROP us a line and we’ll be in touch very soon.
|
125
|
+
|
126
|
+
Email: support@koduc.com
|
127
|
+
|
128
|
+
You can also contact us at +91-120-4540178
|
129
|
+
|
130
|
+
We’d love to hear from you! :) :)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "koduc_express_paypal"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'koduc_express_paypal/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "koduc_express_paypal"
|
8
|
+
spec.version = KoducExpressPaypal::VERSION
|
9
|
+
spec.authors = ["Koduc"]
|
10
|
+
spec.email = ["ratan@ksolves.com"]
|
11
|
+
|
12
|
+
spec.summary = "Gem deals with express checkout one time Paypal Payment using NVP Gateway."
|
13
|
+
spec.description = "Ks Express Paypal is a simple gem used for Paypal Payment Gateway integration. This gem is written by KSolves. The main aim of this project is to deal with the one time Paypal payment using express checkout method using NVP(Name Value Pair)."
|
14
|
+
spec.homepage = "https://github.com/kartiksolves/koduc-paypal-express"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
|
34
|
+
# Add run time dependency of the following gems
|
35
|
+
# required for building the express checkout using NVP
|
36
|
+
spec.add_dependency 'activesupport', '>=3.2'
|
37
|
+
spec.add_dependency "rest-client", '~> 1.4'
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Module is loaded so as to raise the Api Errors
|
2
|
+
# Inherit from the StandardError class
|
3
|
+
# StandardError deals with application level errors
|
4
|
+
# Avoiding the risk of catching errors that deals with the environment
|
5
|
+
# Instantiate the KsAPIErrors class and initialize the object's constructor
|
6
|
+
# Call ks_error_messages method to provide a format to the Error messages raised through API
|
7
|
+
|
8
|
+
|
9
|
+
module KsExceptionHandling
|
10
|
+
class KsAPIErrors < StandardError
|
11
|
+
|
12
|
+
attr_accessor :ks_response
|
13
|
+
|
14
|
+
def initialize(ks_response)
|
15
|
+
@response_array = []
|
16
|
+
@ks_response = ks_response
|
17
|
+
end
|
18
|
+
|
19
|
+
def ks_error_messages
|
20
|
+
@response_array << ks_response
|
21
|
+
response = {success: false ,response:@response_array}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module KsCheckEnvironment
|
2
|
+
|
3
|
+
# Declare the Endpoints according to the environment
|
4
|
+
# Endpoints are required to make a post call through Rest Client
|
5
|
+
# the constant ks_production holds the endpoint for making API call with live credentials
|
6
|
+
# the constant ks_sandbox holds the endpoint for making API call with sandbox credentials
|
7
|
+
KSENDPOINT =
|
8
|
+
{
|
9
|
+
:ks_production=> 'https://api-3t.paypal.com/nvp',
|
10
|
+
:ks_sandbox=> 'https://api-3t.sandbox.paypal.com/nvp'
|
11
|
+
}
|
12
|
+
|
13
|
+
# @@ks_sandbox : A class variable that will decide the environment
|
14
|
+
# Set boolean value for this variable before making an API call
|
15
|
+
# Default is set for sandbox
|
16
|
+
# true for sandbox
|
17
|
+
# false for production
|
18
|
+
@@ks_sandbox = true
|
19
|
+
|
20
|
+
# Call this method to check the value of ks_sandbox variable after initialization
|
21
|
+
def self.ks_sandbox?
|
22
|
+
@@ks_sandbox
|
23
|
+
end
|
24
|
+
|
25
|
+
# Call this method to set the environment
|
26
|
+
# pass ks_boolean_value as true for sandbox
|
27
|
+
# And false for Live environemnt
|
28
|
+
def self.ks_sandbox(ks_boolean_value)
|
29
|
+
@@ks_sandbox = ks_boolean_value
|
30
|
+
end
|
31
|
+
|
32
|
+
# Invoke this method to set the endpoints according to the value of ks_sandbox variable
|
33
|
+
def self.ks_endpoint
|
34
|
+
if ks_sandbox?
|
35
|
+
KsCheckEnvironment::KSENDPOINT[:ks_sandbox]
|
36
|
+
else
|
37
|
+
KsCheckEnvironment::KSENDPOINT[:ks_production]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# Module is loaded for making requests
|
2
|
+
# Initialize the object's constructor first
|
3
|
+
# version :=> Version of the API used
|
4
|
+
# params :=> To hold the parameters passed by the gem user
|
5
|
+
# payment_amount :=> To hold the amount passed by the user
|
6
|
+
# payment_action :=> To hold the action of the payment. default it is 'SALE'
|
7
|
+
# payment_currency :=> Currency used ex: USD
|
8
|
+
# cancel_url :=> URL to which the user is redirected when he/she cancels the payment
|
9
|
+
# return_url :=> URL to which the user is redirected upon the successful completion of the payment
|
10
|
+
|
11
|
+
module KsExpressPaypal
|
12
|
+
class KsRequest
|
13
|
+
|
14
|
+
attr_accessor :version, :params, :payment_amount, :payment_action, :payment_currency, :cancel_url, :return_url
|
15
|
+
|
16
|
+
def initialize(params)
|
17
|
+
@payment_amount = params[:payment_amount]
|
18
|
+
@payment_action = params[:payment_action]
|
19
|
+
@payment_currency = params[:payment_currency]
|
20
|
+
@cancel_url = params[:cancel_url]
|
21
|
+
@return_url = params[:return_url]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Method to check the endpoint
|
25
|
+
# The value is calculated according to the user's choice
|
26
|
+
def self.ks_endpoint
|
27
|
+
ks_env = KsCheckEnvironment.ks_endpoint
|
28
|
+
end
|
29
|
+
|
30
|
+
# Method to dissociate the payment details passed by the user
|
31
|
+
# The parameters are dissociate so that they can be easily utilised in the further API call
|
32
|
+
def ks_payment_details
|
33
|
+
ks_payment_details = {
|
34
|
+
:PAYMENTREQUEST_0_AMT => payment_amount,
|
35
|
+
:PAYMENTREQUEST_0_PAYMENTACTION => payment_action,
|
36
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => payment_currency
|
37
|
+
}
|
38
|
+
return ks_payment_details
|
39
|
+
end
|
40
|
+
|
41
|
+
# Method to fetch the Redirect URLS
|
42
|
+
def ks_redirect_urls
|
43
|
+
ks_redirect_urls = {
|
44
|
+
:cancelUrl=> cancel_url,
|
45
|
+
:returnUrl=> return_url
|
46
|
+
}
|
47
|
+
return ks_redirect_urls
|
48
|
+
end
|
49
|
+
|
50
|
+
# Method to check the validity of the parameters before they are passed to the API call
|
51
|
+
# Initialize the KsValidation class object's constructor present in the KsAPIValidation module
|
52
|
+
# Initialize with the details send by the user through the app
|
53
|
+
# The method will return true if everything is properly validated
|
54
|
+
# Else it will return the response generated
|
55
|
+
# Format of the response "response = {success:true/false,response:[error message]}"
|
56
|
+
# Error message in case success is false
|
57
|
+
# For true value of success it is blank
|
58
|
+
# Will have to validate by the user
|
59
|
+
def valid?
|
60
|
+
validation_obj = KsAPIValidation::KsValidation.new(KsExpressPaypal.ks_merchants_details,ks_payment_details,ks_redirect_urls)
|
61
|
+
response = validation_obj.check_validity
|
62
|
+
return response
|
63
|
+
end
|
64
|
+
|
65
|
+
# SetExpressCheckout method will set the express checkout method
|
66
|
+
# Parameters : Merchant details, payment details and the redirect urls
|
67
|
+
# Method will return a Token that will be utilised further on successful completion
|
68
|
+
# For any error message an error response will be generated
|
69
|
+
# Format of the error response "response = {success:false,response:[error message]}"
|
70
|
+
# Format of the success response "response = {success:true,response:[response generated by Paypal]}"
|
71
|
+
# Call ks_request method everytime for making a request to the API
|
72
|
+
def ks_set_express_checkout
|
73
|
+
ks_response = KsExpressPaypal::KsRequest.ks_request :SetExpressCheckout,KsExpressPaypal.ks_merchants_details.merge(ks_payment_details).merge(ks_redirect_urls)
|
74
|
+
end
|
75
|
+
|
76
|
+
# The app must invoke this method after the user redirection to the paypal's site
|
77
|
+
# GetExpressCheckoutDetails method will return the details of the checkout
|
78
|
+
# It will return the Payer id on successful invocation of the API utilised further
|
79
|
+
# For any error message an error response will be generated
|
80
|
+
# Format of the error response "response = {success:false,response:[error message]}"
|
81
|
+
# Format of the success response "response = {success:true,response:[response generated by Paypal]}"
|
82
|
+
def self.ks_checkout_details(ks_token)
|
83
|
+
ks_response = ks_request :GetExpressCheckoutDetails,KsExpressPaypal.ks_merchants_details.merge(:TOKEN=>ks_token)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Call this method for completing the checkout
|
87
|
+
# Pass the token, payer_id and token as the parameters
|
88
|
+
# Returns the response in the format written same as the above API
|
89
|
+
# Firstly call GetExpressCheckoutDetails to find out the details of the checkout
|
90
|
+
# If the required details are found it will call DoExpressCheckoutPayment method to do the complete process else will return the error message.
|
91
|
+
def self.ks_do_checkout(ks_token,ks_payment_action,ks_payer_id)
|
92
|
+
ks_response = ks_request :GetExpressCheckoutDetails,KsExpressPaypal.ks_merchants_details.merge(:TOKEN=>ks_token)
|
93
|
+
if ks_response[:response][0].is_a? Hash
|
94
|
+
ks_do_checkout = ks_request :DoExpressCheckoutPayment,KsExpressPaypal.ks_merchants_details.merge({
|
95
|
+
:PAYMENTREQUEST_0_AMT => ks_response[:response][0][:PAYMENTREQUEST_0_AMT],
|
96
|
+
:PAYMENTREQUEST_0_PAYMENTACTION => ks_payment_action,
|
97
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => ks_response[:response][0][:PAYMENTREQUEST_0_CURRENCYCODE]
|
98
|
+
}).merge(:TOKEN=>ks_token,:PAYERID=>ks_payer_id)
|
99
|
+
else
|
100
|
+
return ks_response
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# method that will make all the API request
|
105
|
+
# Call ks_handle_response method to handle each request
|
106
|
+
# ks_post_request for every post request
|
107
|
+
def self.ks_request(ks_method,ks_params)
|
108
|
+
ks_handle_response do
|
109
|
+
ks_response = ks_post_request ks_method,ks_params
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Call this method for post request through Rest Client
|
114
|
+
# Pass endpoint calculated above with the parameters with the requested method
|
115
|
+
def self.ks_post_request(ks_method,ks_parameters)
|
116
|
+
RestClient.post(ks_endpoint,ks_parameters.merge(:METHOD=>ks_method))
|
117
|
+
end
|
118
|
+
|
119
|
+
# call this method to handle each response return through the Paypal API
|
120
|
+
# collect the response and decode using CGI parsing and form key value pair
|
121
|
+
# If the ACK is Success or SuccessWithWarning call the custom response with the response message returned
|
122
|
+
# Else return the Error message
|
123
|
+
def self.ks_handle_response
|
124
|
+
ks_response = yield
|
125
|
+
ks_response = CGI.parse(ks_response).inject({}) do |ks_res, (ks_key, ks_value)|
|
126
|
+
ks_res.merge(ks_key.to_sym => ks_value.first)
|
127
|
+
end
|
128
|
+
case ks_response[:ACK]
|
129
|
+
when 'Success', 'SuccessWithWarning'
|
130
|
+
success = KsResponse.new(ks_response)
|
131
|
+
success.ks_success_messages
|
132
|
+
else
|
133
|
+
error_messages = ks_response[:L_LONGMESSAGE0]
|
134
|
+
error = KsExceptionHandling::KsAPIErrors.new(error_messages)
|
135
|
+
error.ks_error_messages
|
136
|
+
end
|
137
|
+
rescue => exc
|
138
|
+
if !exc.message.nil?
|
139
|
+
error = KsExceptionHandling::KsAPIErrors.new(exc.message)
|
140
|
+
error.ks_error_messages
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Return the custom response generated by Paypal APIS
|
2
|
+
# Inherit the StandardError not Exception
|
3
|
+
class KsResponse < StandardError
|
4
|
+
attr_accessor :ks_response
|
5
|
+
|
6
|
+
def initialize(ks_response)
|
7
|
+
@response_array = []
|
8
|
+
@ks_response = ks_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def ks_success_messages
|
12
|
+
@response_array << ks_response
|
13
|
+
response = {success: true ,response:@response_array}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# Methods of the module will validate the parameters passed by the user
|
2
|
+
# Initialise the object's constructor of the class
|
3
|
+
# ks_merchants_details => For holding the paypal credentials
|
4
|
+
# ks_payment_details => For holding the payment details
|
5
|
+
# ks_redirect_urls => For holding the redirect URLS
|
6
|
+
# ks_error => Array for holding the error messages
|
7
|
+
|
8
|
+
module KsAPIValidation
|
9
|
+
class KsValidation
|
10
|
+
|
11
|
+
attr_accessor :ks_merchants_details, :ks_payment_details, :ks_redirect_urls, :ks_error
|
12
|
+
|
13
|
+
def initialize(ks_merchants_details,ks_payment_details,ks_redirect_urls)
|
14
|
+
@ks_merchants_details = ks_merchants_details
|
15
|
+
@ks_payment_details = ks_payment_details
|
16
|
+
@ks_redirect_urls = ks_redirect_urls
|
17
|
+
@ks_error = []
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# It is the first method that is to be called to check the validity of the parameters
|
22
|
+
# The method invokes all the methods of validation and return true if the parameters are verified
|
23
|
+
def check_validity
|
24
|
+
success = true
|
25
|
+
if !empty_values?
|
26
|
+
success = false
|
27
|
+
else
|
28
|
+
success = false if !paypal_credentials?
|
29
|
+
success = false if !mandatory_paypal_details?
|
30
|
+
success = false if !mandatory_payment_details?
|
31
|
+
success = false if !mandatory_url_details?
|
32
|
+
success = false if !check_payment_amount?
|
33
|
+
success = false if !payment_number?
|
34
|
+
success = false if !payment_action?
|
35
|
+
success = false if !currency_code?
|
36
|
+
end
|
37
|
+
response = validate_response(success)
|
38
|
+
return response
|
39
|
+
end
|
40
|
+
|
41
|
+
# It returns the response in both the cases (success or failure)
|
42
|
+
# The format of response is {success: true/false, error_messages: array of the error messages(blank if success is true)}
|
43
|
+
# Check the uniqueness of the array of the error messages with uniq keyword
|
44
|
+
def validate_response(success)
|
45
|
+
unique_errors = ks_error.uniq
|
46
|
+
response = {success:success,response:unique_errors}
|
47
|
+
return response
|
48
|
+
end
|
49
|
+
|
50
|
+
# The method below checks if the parameters passed are completely empty or not
|
51
|
+
# Returns true and false accordingly
|
52
|
+
def empty_values?
|
53
|
+
if ks_merchants_details.empty?
|
54
|
+
ks_error << 'Missing Parameters : Paypal credentials are missing.'
|
55
|
+
puts "Check for Empty values is failed."
|
56
|
+
success = false
|
57
|
+
else
|
58
|
+
puts "Check for Empty values is successful."
|
59
|
+
success = true
|
60
|
+
end
|
61
|
+
return success
|
62
|
+
end
|
63
|
+
|
64
|
+
# The method checks the keys passed by the user in the paypal credentials are correct or not.
|
65
|
+
# These are necessary else the API will through error
|
66
|
+
# Returns true and false accordingly
|
67
|
+
# If false the Error message will be stored in the ks_error
|
68
|
+
def paypal_credentials?
|
69
|
+
if [:USER, :PWD, :SIGNATURE].all? { |s| ks_merchants_details.key? s }
|
70
|
+
success = true
|
71
|
+
puts "Check for the keys of Paypal Credentials is successful."
|
72
|
+
else
|
73
|
+
ks_error << 'Keys Missing : Some of the keys in Paypal credentials are missing.'
|
74
|
+
success = false
|
75
|
+
puts "Check for the keys of Paypal Credentials is failed."
|
76
|
+
end
|
77
|
+
return success
|
78
|
+
end
|
79
|
+
|
80
|
+
# Check if all the mandatory keys in the Paypal credentials have values
|
81
|
+
# Returns true or false accordingly
|
82
|
+
# Error message if false
|
83
|
+
def mandatory_paypal_details?
|
84
|
+
if ks_merchants_details[:USER].blank? || ks_merchants_details[:PWD].blank? || ks_merchants_details[:SIGNATURE].blank? || ks_merchants_details[:VERSION].blank?
|
85
|
+
ks_error << 'Paypal Credentials : Mandatory fields cannot be blank.'
|
86
|
+
success = false
|
87
|
+
puts "Check for the mandatory paypal credentials is failed."
|
88
|
+
else
|
89
|
+
success = true
|
90
|
+
puts "Check for the mandatory paypal credentials is successful."
|
91
|
+
end
|
92
|
+
return success
|
93
|
+
end
|
94
|
+
|
95
|
+
# Check if all the mandatory keys in the Payment have values
|
96
|
+
# Returns true or false accordingly
|
97
|
+
# Error message if false
|
98
|
+
def mandatory_payment_details?
|
99
|
+
if ks_payment_details[:PAYMENTREQUEST_0_AMT].blank? || ks_payment_details[:PAYMENTREQUEST_0_PAYMENTACTION].blank? || ks_payment_details[:PAYMENTREQUEST_0_CURRENCYCODE].blank?
|
100
|
+
ks_error << 'Payment Details : Mandatory fields cannot be blank.'
|
101
|
+
success = false
|
102
|
+
puts "Check for mandatory payment details is failed."
|
103
|
+
else
|
104
|
+
success = true
|
105
|
+
puts "Check for mandatory payment details is successful."
|
106
|
+
end
|
107
|
+
return success
|
108
|
+
end
|
109
|
+
|
110
|
+
# Check if all the mandatory keys in the Redirect URLS have values
|
111
|
+
# Returns true or false accordingly
|
112
|
+
# Error message if false
|
113
|
+
def mandatory_url_details?
|
114
|
+
if ks_redirect_urls[:cancelUrl].blank? || ks_redirect_urls[:returnUrl].blank?
|
115
|
+
ks_error << ' Redirect URLS : Mandatory fields cannot be blank.'
|
116
|
+
success = false
|
117
|
+
puts "Check for mandatory redirect urls is failed."
|
118
|
+
else
|
119
|
+
success = true
|
120
|
+
puts "Check for mandatory redirect urls is successful."
|
121
|
+
end
|
122
|
+
return success
|
123
|
+
end
|
124
|
+
|
125
|
+
# Invoke the below method to check if the payment amount is smaller than or equals to zero
|
126
|
+
# Returns the value of success accordingly
|
127
|
+
def check_payment_amount?
|
128
|
+
if !ks_payment_details[:PAYMENTREQUEST_0_AMT].blank?
|
129
|
+
amount = ks_payment_details[:PAYMENTREQUEST_0_AMT].to_i
|
130
|
+
if !(amount <= 0)
|
131
|
+
success = true
|
132
|
+
puts "Check for payment amount is successful"
|
133
|
+
else
|
134
|
+
ks_error << "Payment Amount is invalid."
|
135
|
+
success = false
|
136
|
+
puts "Check for payment Amount is failed."
|
137
|
+
end
|
138
|
+
return success
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check if the string passed consists of only numbers and the decimal values
|
143
|
+
# Returns true and false accordingly
|
144
|
+
# Returns the error message if success is false
|
145
|
+
def payment_number?
|
146
|
+
if !ks_payment_details[:PAYMENTREQUEST_0_AMT].blank?
|
147
|
+
if ks_payment_details[:PAYMENTREQUEST_0_AMT] =~ /\A[-+]?\d*\.?\d+\z/
|
148
|
+
success = true
|
149
|
+
puts "Check for payment amount is successful."
|
150
|
+
else
|
151
|
+
ks_error << "Payment Amount is invalid."
|
152
|
+
success = false
|
153
|
+
puts "Check for payment amount is failed."
|
154
|
+
end
|
155
|
+
return success
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Check if the string passed consists of only alphabets and the decimal values
|
160
|
+
# Returns true and false accordingly
|
161
|
+
# Returns the error message if false
|
162
|
+
def payment_action?
|
163
|
+
if !ks_payment_details[:PAYMENTREQUEST_0_PAYMENTACTION].blank?
|
164
|
+
if ks_payment_details[:PAYMENTREQUEST_0_PAYMENTACTION].match(/^[a-zA-Z]+$/)
|
165
|
+
success = true
|
166
|
+
puts "Check for payment action is successful."
|
167
|
+
else
|
168
|
+
ks_error << 'Payment Action is invalid.'
|
169
|
+
success = false
|
170
|
+
puts "Check for payment action is failed."
|
171
|
+
end
|
172
|
+
return success
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# Check if the currency code is invalid (contains capital letters)
|
177
|
+
# Returns true and false accordingly
|
178
|
+
# Returns the error message
|
179
|
+
def currency_code?
|
180
|
+
if !ks_payment_details[:PAYMENTREQUEST_0_CURRENCYCODE].blank?
|
181
|
+
if ks_payment_details[:PAYMENTREQUEST_0_CURRENCYCODE].match(/^[A-Z]+$/)
|
182
|
+
success = true
|
183
|
+
puts "Check for currency code is successful."
|
184
|
+
else
|
185
|
+
ks_error << 'Currency Code is invalid'
|
186
|
+
success = false
|
187
|
+
puts "Check for currency code is failed."
|
188
|
+
end
|
189
|
+
return success
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This is the first file to be loaded when this gem is firstly installed
|
2
|
+
# Require each file here
|
3
|
+
|
4
|
+
require "koduc_express_paypal/version"
|
5
|
+
require "koduc_express_paypal/koduc_check_environment"
|
6
|
+
require "koduc_express_paypal/koduc_request"
|
7
|
+
require "koduc_express_paypal/koduc_validation"
|
8
|
+
require "koduc_exception_handling/koduc_api_errors"
|
9
|
+
require "koduc_express_paypal/koduc_response"
|
10
|
+
require "active_support"
|
11
|
+
require "active_support/core_ext"
|
12
|
+
require "rest_client"
|
13
|
+
|
14
|
+
# Declare a constant api_version
|
15
|
+
# This is the release version of the developing API used in this gem
|
16
|
+
# One of the parameters mandatory for each call
|
17
|
+
# No need to pass it from the user's side
|
18
|
+
# Keep it here and change it from here
|
19
|
+
module KsExpressPaypal
|
20
|
+
mattr_accessor :api_version
|
21
|
+
self.api_version = '88.0'
|
22
|
+
|
23
|
+
# Method to take the paypal credentials
|
24
|
+
# The credentials must be included in the app
|
25
|
+
# Merge the VERSION declared in the KsExpressPaypal module
|
26
|
+
# Value of the VERSION is declared as constant
|
27
|
+
def self.ks_merchants_details
|
28
|
+
begin
|
29
|
+
ks_merchants_details = Rails.configuration.paypal_credentials.merge(VERSION: KsExpressPaypal.api_version)
|
30
|
+
rescue => exc
|
31
|
+
if !exc.message.nil?
|
32
|
+
error = KsExceptionHandling::KsAPIErrors.new(exc.message)
|
33
|
+
error.ks_error_messages
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: koduc_express_paypal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koduc
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
description: Ks Express Paypal is a simple gem used for Paypal Payment Gateway integration.
|
84
|
+
This gem is written by KSolves. The main aim of this project is to deal with the
|
85
|
+
one time Paypal payment using express checkout method using NVP(Name Value Pair).
|
86
|
+
email:
|
87
|
+
- ratan@ksolves.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- .travis.yml
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- koduc_express_paypal.gemspec
|
103
|
+
- lib/koduc_exception_handling/koduc_api_errors.rb
|
104
|
+
- lib/koduc_express_paypal.rb
|
105
|
+
- lib/koduc_express_paypal/koduc_check_environment.rb
|
106
|
+
- lib/koduc_express_paypal/koduc_request.rb
|
107
|
+
- lib/koduc_express_paypal/koduc_response.rb
|
108
|
+
- lib/koduc_express_paypal/koduc_validation.rb
|
109
|
+
- lib/koduc_express_paypal/version.rb
|
110
|
+
homepage: https://github.com/kartiksolves/koduc-paypal-express
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.3
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Gem deals with express checkout one time Paypal Payment using NVP Gateway.
|
134
|
+
test_files: []
|
135
|
+
has_rdoc:
|