Skip to content

Commit 64174d4

Browse files
committed
Updates for Magento
1 parent e7d710b commit 64174d4

5 files changed

Lines changed: 193 additions & 111 deletions

File tree

lib/Payplug/Payment.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Payment
1919
*/
2020

2121

22-
public static function retrieve($data, Payplug $payplug = null, $isHostedField = false)
22+
public static function retrieve($data, $payplug = null, $isHostedField = false)
2323
{
2424
return Resource\Payment::retrieve($data, $payplug, $isHostedField);
2525
}
@@ -59,7 +59,7 @@ public static function abort($paymentId, $payplug = null)
5959
* @return Resource\Payment|null The captured payment or null on error.
6060
* @throws Exception\ConfigurationNotSetException
6161
*/
62-
public static function capture($paymentId, Payplug $payplug = null)
62+
public static function capture($paymentId, $payplug = null)
6363
{
6464
$payment = Resource\Payment::fromAttributes(array('id' => $paymentId));
6565
return $payment->capture($payplug);
@@ -72,7 +72,7 @@ public static function capture($paymentId, Payplug $payplug = null)
7272
* @param $is_hosted_field
7373
* @return mixed
7474
*/
75-
public static function authorize($data, Payplug $payplug = null, $is_hosted_field = false)
75+
public static function authorize($data, $payplug = null, $is_hosted_field = false)
7676
{
7777
return Resource\Payment::authorize($data, $payplug, $is_hosted_field);
7878

@@ -100,7 +100,7 @@ public static function create(array $data, $payplug = null)
100100
* @param int $perPage number of results per page
101101
* @param int $page the page number
102102
* @param Payplug $payplug the client configuration
103-
*
103+
*
104104
* @return null|Resource\Payment[] the array of payments
105105
*
106106
* @throws Exception\InvalidPaymentException
@@ -109,5 +109,5 @@ public static function create(array $data, $payplug = null)
109109
public static function listPayments($perPage = null, $page = null, $payplug = null)
110110
{
111111
return Resource\Payment::listPayments($perPage, $page, $payplug);
112-
}
113-
};
112+
}
113+
};

lib/Payplug/Refund.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class Refund {
88
/**
99
* Creates a refund on a payment.
1010
*
11-
* @param string|Payment $payment the payment id or the payment object
11+
* @param string|Payment|array $payment the payment id or the payment object
1212
* @param array $data API data for refund
1313
* @param Payplug $payplug the client configuration
1414
* @param $is_hosted_field indicates if the payment is using hosted fields
1515
*
1616
* @return null|Refund the refund object
1717
* @throws Exception\ConfigurationNotSetException
1818
*/
19-
public static function create($payment, array $data = null, Payplug $payplug = null, $is_hosted_field = false)
19+
public static function create($payment, $data = null, $payplug = null, $is_hosted_field = false)
2020
{
2121
return Resource\Refund::create($payment, $data, $payplug, $is_hosted_field);
2222
}
@@ -52,4 +52,4 @@ public static function listRefunds($payment, $payplug = null)
5252
{
5353
return Resource\Refund::listRefunds($payment, $payplug);
5454
}
55-
}
55+
}

lib/Payplug/Resource/Payment.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,31 @@ public function abort($payplug = null)
126126
/**
127127
* Captures a Payment.
128128
*
129-
* @param Payplug\Payplug $payplug the client configuration
129+
* @param Payplug\Payplug|null $payplug the client configuration
130+
* @param array|null $hostFieldsPayload
130131
*
131-
* @return null|Payment the captured payment or null on error
132+
* @return null|Payment the captured payment or null on error
132133
*
133-
* @throws Payplug\Exception\ConfigurationNotSetException
134+
* @throws Payplug\Exception\ConfigurationNotSetException
134135
*/
135-
public function capture(Payplug\Payplug $payplug = null)
136+
public function capture($payplug = null, $hostFieldsPayload = null)
136137
{
137138
if ($payplug === null) {
138139
$payplug = Payplug\Payplug::getDefaultConfiguration();
139140
}
140141

141142
$httpClient = new Payplug\Core\HttpClient($payplug);
143+
144+
if ($hostFieldsPayload !== null) {
145+
$response = $httpClient->post(
146+
Payplug\Core\APIRoutes::$HOSTED_FIELDS_RESOURCE,
147+
$hostFieldsPayload,
148+
false
149+
);
150+
151+
return $response['httpResponse'];
152+
}
153+
142154
$response = $httpClient->patch(
143155
Payplug\Core\APIRoutes::getRoute(Payplug\Core\APIRoutes::PAYMENT_RESOURCE, $this->id),
144156
array('captured' => true)
@@ -151,15 +163,15 @@ public function capture(Payplug\Payplug $payplug = null)
151163
* @description Authorize a Payment.
152164
* @param $data
153165
* @param Payplug\Payplug|null $payplug
154-
* @param $is_hosted_field
166+
* @param bool $is_hosted_field
155167
* @return mixed|void
156168
* @throws Payplug\Exception\ConfigurationNotSetException
157169
* @throws Payplug\Exception\ConnectionException
158170
* @throws Payplug\Exception\HttpException
159171
* @throws Payplug\Exception\UndefinedAttributeException
160172
* @throws Payplug\Exception\UnexpectedAPIResponseException
161173
*/
162-
public static function authorize($data, Payplug\Payplug $payplug = null, $is_hosted_field = false)
174+
public static function authorize($data, $payplug = null, $is_hosted_field = false)
163175
{
164176
if ($payplug === null) {
165177
$payplug = Payplug\Payplug::getDefaultConfiguration();
@@ -182,15 +194,15 @@ public static function authorize($data, Payplug\Payplug $payplug = null, $is_hos
182194
/**
183195
* @param $data
184196
* @param Payplug\Payplug|null $payplug
185-
* @param $is_hosted_field
197+
* @param bool $is_hosted_field
186198
* @return array|Payment
187199
* @throws Payplug\Exception\ConfigurationNotSetException
188200
* @throws Payplug\Exception\ConnectionException
189201
* @throws Payplug\Exception\HttpException
190202
* @throws Payplug\Exception\UndefinedAttributeException
191203
* @throws Payplug\Exception\UnexpectedAPIResponseException
192204
*/
193-
public static function retrieve($data, Payplug\Payplug $payplug = null, $is_hosted_field = false)
205+
public static function retrieve($data, $payplug = null, $is_hosted_field = false)
194206
{
195207
if ($payplug === null) {
196208
$payplug = Payplug\Payplug::getDefaultConfiguration();

lib/Payplug/Resource/Refund.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public static function fromAttributes(array $attributes)
2424
/**
2525
* Creates a refund on a payment.
2626
*
27-
* @param string|Payment $refund_data the payment id or the payment object
27+
* @param string|Payment|array $refund_data the payment id or the payment object
2828
* @param array $data API data for refund
2929
* @param Payplug\Payplug $payplug the client configuration
30-
* @param $is_hosted_field
30+
* @param bool $is_hosted_field
3131
*
3232
* @return null|Refund the refund object
3333
* @throws Payplug\Exception\ConfigurationNotSetException
3434
*/
35-
public static function create($refund_data, array $data = null, Payplug\Payplug $payplug = null, $is_hosted_field = false)
35+
public static function create($refund_data, $data = null, $payplug = null, $is_hosted_field = false)
3636
{
3737
if ($payplug === null) {
3838
$payplug = Payplug\Payplug::getDefaultConfiguration();

0 commit comments

Comments
 (0)