Overview
  • Namespace
  • Class

Namespaces

  • Omnipay
    • Pagarme
      • Message

Classes

  • Omnipay\Pagarme\CreditCard
  • Omnipay\Pagarme\Gateway
  • Omnipay\Pagarme\Message\AbstractRequest
  • Omnipay\Pagarme\Message\AuthorizeRequest
  • Omnipay\Pagarme\Message\CaptureRequest
  • Omnipay\Pagarme\Message\CreateCardRequest
  • Omnipay\Pagarme\Message\CreateCustomerRequest
  • Omnipay\Pagarme\Message\InstallmentsRequest
  • Omnipay\Pagarme\Message\PurchaseRequest
  • Omnipay\Pagarme\Message\RefundRequest
  • Omnipay\Pagarme\Message\Response
  • Omnipay\Pagarme\Message\VoidRequest
  1 <?php
  2 
  3 namespace Omnipay\Pagarme;
  4 
  5 use Omnipay\Common\AbstractGateway;
  6 
  7 /**
  8  * Pagarme Gateway
  9  *
 10  * Example:
 11  *
 12  * <code>
 13  *   // Create a gateway for the Pagarme Gateway
 14  *   // (routes to GatewayFactory::create)
 15  *   $gateway = Omnipay::create('Pagarme');
 16  *
 17  *   // Initialise the gateway
 18  *   $gateway->initialize(array(
 19  *       'apiKey' => 'MyApiKey',
 20  *   ));
 21  *
 22  *   // Create a credit card object
 23  *   // This card can be used for testing.
 24  *   $card = new CreditCard(array(
 25  *               'firstName'    => 'Example',
 26  *               'lastName'     => 'Customer',
 27  *               'number'       => '4242424242424242',
 28  *               'expiryMonth'  => '01',
 29  *               'expiryYear'   => '2020',
 30  *               'cvv'          => '123',
 31  *               'email'        => 'customer@example.com',
 32  *               'address1'     => 'Street name, Street number, Neighborhood',
 33  *               'address2'     => 'address complementary',
 34  *               'postcode'     => '05443100',
 35  *               'phone'        => '19 3242 8855',
 36  *               'holder_document_number' => '214.278.589-40',
 37  *   ));
 38  *
 39  *   // Do an authorize transaction on the gateway
 40  *   $transaction = $gateway->authorize(array(
 41  *       'amount'           => '10.00',
 42  *       'soft_descriptor'  => 'test',
 43  *       'payment_method'   => 'credit_card',
 44  *       'card'             => $card,
 45  *       'metadata'         => array(
 46  *                                 'product_id' => 'ID1111',
 47  *                                 'invoice_id' => 'IV2222',
 48  *                             ),
 49  *   ));
 50  *   $response = $transaction->send();
 51  *   if ($response->isSuccessful()) {
 52  *       echo "Authorize transaction was successful!\n";
 53  *       $sale_id = $response->getTransactionReference();
 54  *       $customer_id = $response->getCustomerReference();
 55  *       $card_id = $response->getCardReference();
 56  *       echo "Transaction reference = " . $sale_id . "\n";
 57  *   }
 58  * </code>
 59  *
 60  * Test modes:
 61  *
 62  * Pagarme accounts have test-mode API keys as well as live-mode
 63  * API keys. Data created with test-mode credentials will never 
 64  * hit the credit card networks and will never cost anyone money.
 65  *
 66  * Unlike some gateways, there is no test mode endpoint separate
 67  * to the live mode endpoint, the Pagarme API endpoint is the same
 68  * for test and for live.
 69  *
 70  * Setting the testMode flag on this gateway has no effect.  To
 71  * use test mode just use your test mode API key.
 72  *
 73  * Authentication:
 74  *
 75  * Authentication is by means of a single secret API key set as
 76  * the apiKey parameter when creating the gateway object.
 77  *
 78  * @see \Omnipay\Common\AbstractGateway
 79  * @see \Omnipay\Pagarme\Message\AbstractRequest
 80  * @link https://docs.pagar.me/
 81  */
 82 class Gateway extends AbstractGateway
 83 {
 84     public function getName()
 85     {
 86         return 'Pagarme';
 87     }
 88     
 89     /**
 90      * Get the gateway parameters
 91      *
 92      * @return array
 93      */
 94     public function getDefaultParameters()
 95     {
 96         return array(
 97             'apiKey' => '',
 98         );
 99     }
100     
101     /**
102      * Get the gateway API Key
103      *
104      * Authentication is by means of a single secret API key set as
105      * the apiKey parameter when creating the gateway object.
106      *
107      * @return string
108      */
109     public function getApiKey()
110     {
111         return $this->getParameter('apiKey');
112     }
113     
114     /**
115      * Set the gateway API Key
116      *
117      * Authentication is by means of a single secret API key set as
118      * the apiKey parameter when creating the gateway object.
119      *
120      * Pagarme accounts have test-mode API keys as well as live-mode
121      * API keys. Data created with test-mode credentials will never 
122      * hit the credit card networks and will never cost anyone money.
123      *
124      * Unlike some gateways, there is no test mode endpoint separate
125      * to the live mode endpoint, the Stripe API endpoint is the same
126      * for test and for live.
127      *
128      * Setting the testMode flag on this gateway has no effect.  To
129      * use test mode just use your test mode API key.
130      *
131      * @param string $value
132      * @return Gateway provides a fluent interface.
133      */
134     public function setApiKey($value)
135     {
136         return $this->setParameter('apiKey', $value);
137     }
138     
139     /**
140      * Authorize Request
141      *
142      * An Authorize request is similar to a purchase request but the
143      * charge issues an authorization (or pre-authorization), and no money
144      * is transferred.  The transaction will need to be captured later
145      * in order to effect payment. Uncaptured charges expire in 5 days.
146      *
147      * Either a card object or card_id is required by default. Otherwise,
148      * you must provide a card_hash, like the ones returned by Pagarme.js
149      * or use the boleto's payment method.
150      * 
151      * Pagarme gateway supports only two types of "payment_method":
152      * 
153      * * credit_card
154      * * boleto
155      * 
156      * Optionally, you can provide the customer details to use the antifraude
157      * feature. These details is passed using the following attributes available
158      * on credit card object:
159      * 
160      * * firstName
161      * * lastName
162      * * address1 (must be in the format "street, street_number and neighborhood")
163      * * address2 (used to specify the optional parameter "street_complementary")
164      * * postcode
165      * * phone (must be in the format "DDD PhoneNumber" e.g. "19 98888 5555")
166      * 
167      * @param array $parameters
168      * @return \Omnipay\Pagarme\Message\AuthorizeRequest
169      */
170     public function authorize(array $parameters = array())
171     {
172         return $this->createRequest('\Omnipay\Pagarme\Message\AuthorizeRequest', $parameters);
173     }
174     
175     /**
176      * Capture Request
177      *
178      * Use this request to capture and process a previously created authorization.
179      *
180      * @param array $parameters
181      * @return \Omnipay\Pagarme\Message\CaptureRequest
182      */
183     public function capture(array $parameters = array())
184     {
185         return $this->createRequest('\Omnipay\Pagarme\Message\CaptureRequest', $parameters);
186     }
187     
188     /**
189      * Purchase request.
190      *
191      * To charge a credit card or generate a boleto you create a new transaction 
192      * object. If your API key is in test mode, the supplied card won't actually 
193      * be charged, though everything else will occur as if in live mode.
194      *
195      * Either a card object or card_id is required by default. Otherwise,
196      * you must provide a card_hash, like the ones returned by Pagarme.js
197      * or use the boleto's payment method.
198      * 
199      * Pagarme gateway supports only two types of "payment_method":
200      * 
201      * * credit_card
202      * * boleto
203      * 
204      * @see https://docs.pagar.me/capturing-card-data/
205      * 
206      * Optionally, you can provide the customer details to use the antifraude
207      * feature. These details is passed using the following attributes available
208      * on credit card object:
209      * 
210      * * firstName
211      * * lastName
212      * * address1 (must be in the format "street, street_number and neighborhood")
213      * * address2 (used to specify the optional parameter "street_complementary")
214      * * postcode
215      * * phone (must be in the format "DDD PhoneNumber" e.g. "19 98888 5555")
216      *
217      * @param array $parameters
218      * @return \Omnipay\Pagarme\Message\PurchaseRequest
219      */
220     public function purchase(array $parameters = array())
221     {
222         return $this->createRequest('\Omnipay\Pagarme\Message\PurchaseRequest', $parameters);
223     }
224     
225     /**
226      * Refund Request
227      *
228      * When you refund, you must specify a transaction reference.
229      *
230      * Creating a new refund will refund a transaction that has
231      * previously been created but not yet charged. Funds will
232      * be refunded to the credit that was originally authorized.
233      *
234      * @param array $parameters
235      * @return \Omnipay\Pagarme\Message\RefundRequest
236      */
237     public function refund(array $parameters = array())
238     {
239         return $this->createRequest('\Omnipay\Pagarme\Message\RefundRequest', $parameters);
240     }
241     
242     /**
243      * Void Transaction Request
244      * 
245      * Pagarme does not support voiding, per se, but
246      * we treat it as a full refund.
247      *
248      * See RefundRequest for additional information
249      *
250      * @param array $parameters
251      * @return \Omnipay\Pagarme\Message\VoidRequest
252      */
253     public function void(array $parameters = array())
254     {
255         return $this->createRequest('\Omnipay\Pagarme\Message\VoidRequest', $parameters);
256     }
257     
258     /**
259      * Create Card
260      *
261      * This call can be used to create a new credit card.  
262      * If a customerReference is passed in then
263      * a card is added to an existing customer.  If there is no
264      * customerReference passed in then a new customer is created.  The
265      * response in that case will then contain both a customer reference
266      * and a card reference, and is essentially the same as CreateCustomerRequest
267      *
268      * @param array $parameters
269      * @return \Omnipay\Pagarme\Message\CreateCardRequest
270      */
271     public function createCard(array $parameters = array())
272     {
273         return $this->createRequest('\Omnipay\Pagarme\Message\CreateCardRequest', $parameters);
274     }
275     
276     /**
277      * Create Customer
278      *
279      * Customer objects allow you to perform recurring charges and
280      * track multiple charges that are associated with the same customer.
281      * The API allows you to create customers.
282      *
283      * @param array $parameters
284      * @return \Omnipay\Pagarme\Message\CreateCustomerRequest
285      */
286     public function createCustomer(array $parameters = array())
287     {
288         return $this->createRequest('\Omnipay\Pagarme\Message\CreateCustomerRequest', $parameters);
289     }
290     
291     /**
292      * Pagarme Calculate Installments Request
293      *
294      * You can use Pagar.me API to calculate installments
295      * for a purchase.
296      * 
297      * @param array $parameters
298      * @return \Omnipay\Pagarme\Message\InstallmentsRequest
299      */
300     public function calculateInstallments(array $parameters = array())
301     {
302         return $this->createRequest('\Omnipay\Pagarme\Message\InstallmentsRequest', $parameters);
303     }
304 }
305 
API documentation generated by ApiGen