| 1 | package Net::Simplify::Authentication; | ||
| 2 | |||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Net::Simplify::Authentication - Simplify Commerce authentication class | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | use Net::Simplify; | ||
| 11 | |||
| 12 | my $auth = Net::Simplify::Authentication->create({ | ||
| 13 | public_key => 'YOUR PUBLIC KEY', | ||
| 14 | private_key => 'YOUR PRIVATE KEY' | ||
| 15 | }); | ||
| 16 | |||
| 17 | my $payment = Net::Simplify::Payment->create({...}, $auth); | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | =head3 create(%params) | ||
| 22 | |||
| 23 | Creates an authentication object using values in the C<params> hash. The authencation | ||
| 24 | object contains three values: C<public_key>, C<private_key> and C<access_token>. The | ||
| 25 | public and private keys are used for all API requests and the access token is required | ||
| 26 | for all OAuth API requests (see L<Net::Simplify::AccessToken>). | ||
| 27 | |||
| 28 | If C<%params> contains C<public_key> this value is used to set the object's public key otherwise | ||
| 29 | the value is taken from the global C<$Net::Simplify::public_key>. | ||
| 30 | If C<%params> contains C<private_key> this value is used to set the object's private key otherwise | ||
| 31 | the value is taken from the global C<$Net::Simplify::private_key>. | ||
| 32 | |||
| 33 | =head3 public_key() | ||
| 34 | |||
| 35 | Returns the value of this object's public_key. | ||
| 36 | |||
| 37 | =head3 private_key() | ||
| 38 | |||
| 39 | Returns the value of this object's private_key. | ||
| 40 | |||
| 41 | =head3 access_token() | ||
| 42 | |||
| 43 | Returns the value of this object's access token. | ||
| 44 | |||
| 45 | =head1 SEE ALSO | ||
| 46 | |||
| 47 | L<Net::Simplify>, | ||
| 48 | L<Net::Simplify::AccessToken>, | ||
| 49 | L<http://www.simplify.com> | ||
| 50 | |||
| 51 | =head1 VERSION | ||
| 52 | |||
| 53 | 1.6.0 | ||
| 54 | |||
| 55 | =head1 LICENSE | ||
| 56 | |||
| 57 | Copyright (c) 2013 - 2022 MasterCard International Incorporated | ||
| 58 | All rights reserved. | ||
| 59 | |||
| 60 | Redistribution and use in source and binary forms, with or without modification, are | ||
| 61 | permitted provided that the following conditions are met: | ||
| 62 | |||
| 63 | Redistributions of source code must retain the above copyright notice, this list of | ||
| 64 | conditions and the following disclaimer. | ||
| 65 | Redistributions in binary form must reproduce the above copyright notice, this list of | ||
| 66 | conditions and the following disclaimer in the documentation and/or other materials | ||
| 67 | provided with the distribution. | ||
| 68 | Neither the name of the MasterCard International Incorporated nor the names of its | ||
| 69 | contributors may be used to endorse or promote products derived from this software | ||
| 70 | without specific prior written permission. | ||
| 71 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
| 72 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 73 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
| 74 | SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 75 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
| 76 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 77 | OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | ||
| 78 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
| 79 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 80 | SUCH DAMAGE. | ||
| 81 | |||
| 82 | =cut | ||
| 83 | |||
| 84 | use 5.006; | ||
| 85 | use strict; | ||
| 86 | use warnings FATAL => 'all'; | ||
| 87 | |||
| 88 | sub create { | ||
| 89 | |||
| 90 | my ($class, $params) = @_; | ||
| 91 | |||
| 92 | my $self = {}; | ||
| 93 | $self->{public_key} = $params->{public_key} if defined $params->{public_key}; | ||
| 94 | $self->{private_key} = $params->{private_key} if defined $params->{private_key}; | ||
| 95 | $self->{access_token} = $params->{access_token} if defined $params->{access_token}; | ||
| 96 | |||
| 97 | $self->{public_key} = $Net::Simplify::public_key unless defined $self->{public_key}; | ||
| 98 | $self->{private_key} = $Net::Simplify::private_key unless defined $self->{private_key}; | ||
| 99 | |||
| 100 | bless $self, $class | ||
| 101 | } | ||
| 102 | |||
| 103 | sub public_key { | ||
| 104 | my ($self, $v) = @_; | ||
| 105 | |||
| 106 | $self->{public_key} = $v if defined $v; | ||
| 107 | |||
| 108 | $self->{public_key}; | ||
| 109 | } | ||
| 110 | |||
| 111 | sub private_key { | ||
| 112 | my ($self, $v) = @_; | ||
| 113 | |||
| 114 | $self->{private_key} = $v if defined $v; | ||
| 115 | |||
| 116 | $self->{private_key}; | ||
| 117 | } | ||
| 118 | |||
| 119 | sub access_token { | ||
| 120 | my ($self, $v) = @_; | ||
| 121 | |||
| 122 | $self->{access_token} = $v if defined $v; | ||
| 123 | |||
| 124 | $self->{access_token}; | ||
| 125 | } | ||
| 126 | |||
| 127 | 1; |