File Coverage

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


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