PaymentPageRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 15 2
A getEndpoint() 0 4 1
1
<?php
2
/**
3
 * Ebanx paymentPage Request.
4
 */
5
namespace Omnipay\Ebanx\Message;
6
7
/**
8
 * Ebanx paymentPage Request
9
 *
10
 * A payment page is a page inside Ebanx domain where the user will be able to
11
 * provide the payment off-site
12
 * cardReference paramenter
13
 *
14
 * Ebanx gateway supports three types of "paymentMethod" for the requestPage:
15
 *
16
 * *_all: all available payment methods for the merchant account in this country.
17
 * *boleto: Boleto Bancário.
18
 * *_creditcard: Credit Card
19
 *
20
 *
21
 * Example:
22
 *
23
 * <code>
24
 *   // Create a gateway for the Ebanx Gateway
25
 *   // (routes to GatewayFactory::create)
26
 *   $gateway = Omnipay::create('Ebanx');
27
 *
28
 *   // Initialise the gateway
29
 *   $gateway->initialize(array(
30
 *       'integration_key' => 'MyApiKey',
31
 *   ));
32
 *
33
 *   // Create a credit card object
34
 *   // This card can be used for testing.
35
 *   $card = new CreditCard(array(
36
 *               'firstName'    => 'Example',
37
 *               'lastName'     => 'Customer',
38
 *               'number'       => '4242424242424242',
39
 *               'expiryMonth'  => '01',
40
 *               'expiryYear'   => '2020',
41
 *               'cvv'          => '123',
42
 *               'email'        => '[email protected]',
43
 *               'address1'     => 'Street name, Street number, Complement',
44
 *               'address2'     => 'Neighborhood',
45
 *               'city'         => 'City',
46
 *               'state'        => 'sp',
47
 *               'country'      => 'BR',
48
 *               'postcode'     => '05443100',
49
 *               'phone'        => '19 3242 8855',
50
 *   ));
51
 *
52
 *   // Do an authorize transaction on the gateway
53
 *   $transaction = $gateway->paymentPage(array(
54
 *       'amount'           => '10.00',
55
 *       'currency'         => 'BRL',
56
 *       'paymentMethod'    => '_all',
57
 *       'card'             => $card,
58
 *   ));
59
 *
60
 *   $response = $transaction->send();
61
 *   if ($response->isRedirect()) {
62
 *       // redirect to offsite payment gateway
63
 *       $response->redirect();
64
 *   } elseif ($response->isSuccessful()) {
65
 *       echo "Authorize transaction was successful!\n";
66
 *       echo "Transaction reference = " . $response->getTransactionReference() . "\n";
67
 *   } else {
68
 *       // payment failed: display message to customer
69
 *       exit($response->getMessage());
70
 *   }
71
 * </code>
72
 *
73
 * @see  \Omnipay\Ebanx\Gateway
74
 * @see  \Omnipay\Ebanx\Message\CaptureRequest
75
 * @link https://developers.ebanxpagamentos.com/api-reference/ebanx-payment-api/ebanx-payment-guide/guide-create-a-payment/brazil/#payment-page-API
76
 */
77
class PaymentPageRequest extends AbstractRequest
78
{
79 6
    public function getData()
80
    {
81 6
        $this->validate('card', 'amount', 'currency', 'transactionId');
82
83 6
        $data                          = $this->getDefaultParameters();
84 6
        $data['name']                  = $this->getCard()->getName();
85 6
        $data['email']                 = $this->getCard()->getEmail();
86 6
        $data['country']               = $this->getCard()->getCountry();
87 6
        $data['payment_type_code']     = $this->getPaymentMethod() ?: '_all';
88 6
        $data['merchant_payment_code'] = $this->getTransactionId();
89 6
        $data['currency_code']         = $this->getCurrency();
90 6
        $data['amount']                = $this->getAmount();
91
92 6
        return $data;
93
    }
94
95
96 6
    public function getEndpoint()
97
    {
98 6
        return parent::getEndpoint() . '/request';
99
    }
100
}
101