File Coverage

blib/lib/Net/Payment/CCAvenue/NonSeamless.pm
Criterion Covered Total %
statement 37 37 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1             package Net::Payment::CCAvenue::NonSeamless;
2              
3 2     2   92360 use Moose;
  2         787560  
  2         13  
4             extends 'Net::Payment::CCAvenue';
5              
6 2     2   13971 use URI;
  2         8503  
  2         89  
7 2     2   1707 use CGI ( ':standard', '-no_debug', '-no_xhtml' );
  2         53798  
  2         11  
8 2     2   7892 use DateTime;
  2         800287  
  2         1119  
9              
10             =head1 NAME
11              
12             Net::Payment::CCAvenue::NonSeamless - Processing orders using CCAvenue billing page!
13              
14             =head1 VERSION
15              
16             Version 0.01
17              
18             =cut
19              
20             our $VERSION = '0.02';
21              
22             =head1 SYNOPSIS
23              
24             CCAvenue billing page (Non-Seamless) - Avoid the hassle of developing and managing your own checkout page. Use the customizable billing page provided by CCAvenue which enables you to collect billing and shipping information of the customer.
25              
26             use Net::Payment::CCAvenue::NonSeamless;
27              
28             my $foo = Net::Payment::CCAvenue::NonSeamless->new(
29             encryption_key => 'xxxx',
30             access_code => 'xxxx',
31             merchant_id => 'xxxxx',
32             currency => 'AED',
33             amount => '3.00',
34             redirect_url => 'http://example.com/order/success_or_fail',
35             cancel_url => 'http://example.com/order/cancel',
36             );
37            
38             # Get NonSeamless integration form
39             $foo->payment_form();
40              
41             # Above method returns html form and your need to render this and click on pay button to start payment.
42              
43             =cut
44              
45             =head1 See More
46              
47             =over 2
48              
49             =item L<Net::Payment::CCAvenue>
50             =item L<Net::Payment::CCAvenue::NonSeamless::Response>
51              
52             =head1 Attributes
53              
54             =head2 request_type
55              
56             Sets the request type. Default as C<JSON>.
57              
58             =head2 response_type
59              
60             Sets the response type. Default as C<JSON>.
61              
62             =head2 request_version
63              
64             Sets the response version. Default as C<1.1>.
65              
66             =cut
67              
68             has [qw(request_type response_type)] => (
69             is => 'ro',
70             isa => 'Str',
71             default => sub { return 'JSON' },
72             );
73              
74             has request_version => (
75             is => 'ro',
76             isa => 'Str',
77             default => sub { return '1.1' },
78             );
79              
80             =head2 order_id
81              
82             Sets the unique order identifier.
83              
84             =cut
85              
86             has order_id => (
87             is => 'ro',
88             isa => 'Str',
89             lazy_build => 1,
90             );
91              
92             sub _build_order_id {
93 1     1   17 my ($self) = @_;
94 1         10 my $dt = DateTime->now;
95 1         449 my $merch_txn_ref = $dt->ymd('') . $dt->hms('') . $dt->millisecond() . $self->customer_email;
96 1         45 return substr( $merch_txn_ref, 0, 24 );
97             }
98              
99             =head2 currency
100              
101             Sets the currency like AED or INR etc.
102              
103             =head2 amount
104              
105             Sets the amount to be paid.
106              
107             =head2 redirect_url
108              
109             Sets your callback url, CCAvenue sends the response back to your callback url with the transaction status.
110              
111             =head2 cancel_url
112              
113             Sets your cancel callback url, CCAvenue sends the response back to your callback url with the transaction status.
114              
115             =cut
116              
117             has [qw(currency amount redirect_url cancel_url)] => (
118             is => 'ro',
119             isa => 'Str',
120             required => 1
121             );
122              
123             =head2 customer_email
124              
125             Sets customer email.
126              
127             =head2 customer_name
128              
129             Sets customer name.
130              
131             =head2 order_description
132              
133             Sets your order description.
134              
135             =head2 extra_param1
136              
137             Sets the extra parameter sends to gateway, it will be returned back, can be used as session identifier.
138              
139             =cut
140              
141             has [qw(customer_email customer_name order_description extra_param1)] => (
142             is => 'ro',
143             isa => 'Str',
144             );
145              
146             =head2 language
147              
148             Sets the language. Default as C<en>.
149              
150             =cut
151              
152             has language => (
153             is => 'ro',
154             isa => 'Str',
155             default => sub { return 'en'; }
156             );
157              
158             =head1 SUBROUTINES/METHODS
159              
160             =head2 payment_form_data
161              
162             Returns required parameter needed for payment gateway as query string format.
163              
164             =cut
165              
166             sub payment_form_data {
167 1     1 1 23 my ($self) = @_;
168 1         10 my $url = URI->new( '', 'http' );
169 1         6201 my $query_params = {
170             'merchant_id' => $self->merchant_id,
171             'order_id' => $self->order_id,
172             'currency' => $self->currency,
173             'amount' => $self->amount,
174             'redirect_url' => $self->redirect_url,
175             'cancel_url' => $self->cancel_url,
176             'language' => $self->language,
177             'merchant_param1' => $self->extra_param1,
178             'response_type' => $self->response_type,
179             'customer_identifier' => $self->customer_email,
180             };
181 1         10 $url->query_form(%$query_params);
182 1         381 return $url->query;
183             }
184              
185             =head2 payment_form
186              
187             Returns payment processing html form.
188              
189             =cut
190              
191             sub payment_form {
192 1     1 1 4 my ($self) = @_;
193              
194 1         17 my $data = $self->payment_form_data();
195              
196 1         19 my $command = 'initiateTransaction';
197 1         34 my $url = $self->service_url;
198 1         6 $url->query_form( 'command' => $command );
199              
200 1         98 my $form;
201 1         7 $form .= start_form(
202             -method => 'POST',
203             -action => $url->as_string,
204             );
205 1         6069 $form .= hidden(
206             -name => 'encRequest',
207             -default => [ $self->encrypt_data($data) ]
208             );
209 1         390 $form .= hidden(
210             -name => 'access_code',
211             -default => [ $self->access_code ]
212             );
213 1         224 $form .= hidden(
214             -name => 'command',
215             -default => [$command]
216             );
217 1         284 $form .= hidden(
218             -name => 'request_type',
219             -default => [ $self->request_type ]
220             );
221 1         252 $form .= hidden(
222             -name => 'response_type',
223             -default => [ $self->response_type ]
224             );
225 1         222 $form .= hidden(
226             -name => 'version',
227             -default => [ $self->request_version ]
228             );
229 1         192 $form .= submit(
230             -name => 'submit',
231             -id => 'paybutton',
232             -value => 'Pay'
233             );
234 1         245 $form .= end_form;
235              
236 1         174 return $form;
237             }
238              
239             =head1 AUTHOR
240              
241             Rakesh Kumar Shardiwal, C<< <rakesh.shardiwal at gmail.com> >>
242              
243             =head1 BUGS
244              
245             Please report any bugs or feature requests to C<bug-net-payment-ccavenue-nonseamless at rt.cpan.org>, or through
246             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Payment-CCAvenue-NonSeamless>. I will be notified, and then you'll
247             automatically be notified of progress on your bug as I make changes.
248              
249             =head1 SUPPORT
250              
251             You can find documentation for this module with the perldoc command.
252              
253             perldoc Net::Payment::CCAvenue::NonSeamless
254              
255              
256             You can also look for information at:
257              
258             =over 4
259              
260             =item * RT: CPAN's request tracker (report bugs here)
261              
262             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Payment-CCAvenue-NonSeamless>
263              
264             =item * AnnoCPAN: Annotated CPAN documentation
265              
266             L<http://annocpan.org/dist/Net-Payment-CCAvenue-NonSeamless>
267              
268             =item * CPAN Ratings
269              
270             L<http://cpanratings.perl.org/d/Net-Payment-CCAvenue-NonSeamless>
271              
272             =item * Search CPAN
273              
274             L<http://search.cpan.org/dist/Net-Payment-CCAvenue-NonSeamless/>
275              
276             =back
277              
278              
279             =head1 ACKNOWLEDGEMENTS
280              
281              
282             =head1 LICENSE AND COPYRIGHT
283              
284             Copyright 2021 Rakesh Kumar Shardiwal.
285              
286             This program is free software; you can redistribute it and/or modify it
287             under the terms of the the Artistic License (2.0). You may obtain a
288             copy of the full license at:
289              
290             L<http://www.perlfoundation.org/artistic_license_2_0>
291              
292             Any use, modification, and distribution of the Standard or Modified
293             Versions is governed by this Artistic License. By using, modifying or
294             distributing the Package, you accept this license. Do not use, modify,
295             or distribute the Package, if you do not accept this license.
296              
297             If your Modified Version has been derived from a Modified Version made
298             by someone other than you, you are nevertheless required to ensure that
299             your Modified Version complies with the requirements of this license.
300              
301             This license does not grant you the right to use any trademark, service
302             mark, tradename, or logo of the Copyright Holder.
303              
304             This license includes the non-exclusive, worldwide, free-of-charge
305             patent license to make, have made, use, offer to sell, sell, import and
306             otherwise transfer the Package with respect to any patent claims
307             licensable by the Copyright Holder that are necessarily infringed by the
308             Package. If you institute patent litigation (including a cross-claim or
309             counterclaim) against any party alleging that the Package constitutes
310             direct or contributory patent infringement, then this Artistic License
311             to you shall terminate on the date that such litigation is filed.
312              
313             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
314             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
315             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
316             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
317             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
318             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
319             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
320             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
321              
322              
323             =cut
324              
325             1; # End of Net::Payment::CCAvenue::NonSeamless