Skip to content

Commit 63d9b11

Browse files
committed
removed some duplicate methods from tranaction interface
1 parent b27bdd0 commit 63d9b11

File tree

6 files changed

+185
-186
lines changed

6 files changed

+185
-186
lines changed

README.md

Lines changed: 149 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -59,151 +59,156 @@ class Transaction extends Model implements TransactionInterface
5959
```
6060
```php
6161
<?php
62-
63-
namespace Tartan\Larapay\Transaction;
64-
65-
interface TransactionInterface
66-
{
67-
/**
68-
* set gateway token of transaction
69-
*
70-
* @param string $token
71-
* @param bool $save
72-
*
73-
* @return mixed
74-
*/
75-
public function setGatewayToken(string $token, bool $save = true): bool;
76-
77-
/**
78-
* set reference ID of transaction
79-
*
80-
* @param string $referenceId
81-
* @param bool $save
82-
*
83-
* @return mixed
84-
*/
85-
public function setReferenceId(string $referenceId, bool $save = true): bool;
86-
87-
/**
88-
* check if transaction is ready for requesting token from payment gateway or not
89-
*
90-
* @return boolean
91-
*/
92-
public function checkForRequestToken(): bool;
93-
94-
/**
95-
* check if transaction is ready for requesting verify method from payment gateway or not
96-
*
97-
* @return bool
98-
*/
99-
public function checkForVerify(): bool;
100-
101-
/**
102-
* check if transaction is ready for requesting inquiry method from payment gateway or not
103-
* This feature does not append to all payment gateways
104-
*
105-
* @return bool
106-
*/
107-
public function checkForInquiry(): bool;
108-
109-
/**
110-
* check if transaction is ready for requesting refund method from payment gateway or not
111-
* This feature does not append to all payment gateways
112-
*
113-
* @return bool
114-
*/
115-
public function checkForRefund(): bool;
116-
117-
/**
118-
* check if transaction is ready for requesting after verify method from payment gateway or not
119-
* This feature does not append to all payment gateways.
120-
* for example in Mellat gateway this method can assume as SETTLE method
121-
*
122-
* @return bool
123-
*/
124-
public function checkForAfterVerify(): bool;
125-
126-
/**
127-
* Set the card number (hash of card number) that used for paying the transaction
128-
* This data does not provide by all payment gateways
129-
*
130-
* @return bool
131-
*/
132-
public function setCardNumber(string $cardNumber): bool;
133-
134-
/**
135-
* Mark transaction as a verified transaction
136-
*
137-
* @return bool
138-
*/
139-
public function setVerified(): bool;
140-
141-
/**
142-
* Mark transaction as a after verified transaction
143-
* For example SETTLED in Mellat gateway
144-
*
145-
* @return bool
146-
*/
147-
public function setAfterVerified(): bool;
148-
149-
/**
150-
* Mark transaction as a paid/successful transaction
151-
*
152-
* @return bool
153-
*/
154-
public function setPaid(): bool;
155-
156-
/**
157-
* Mark transaction as a refunded transaction
158-
*
159-
* @return bool
160-
*/
161-
public function setRefunded(): bool;
162-
163-
/**
164-
* Returns the payable amount af the transaction
165-
* @return int
166-
*/
167-
public function getAmount(): int;
168-
169-
/**
170-
* Set the paid time of the transaction.
171-
* You can set this value in setPaid() method too and bypass this function
172-
*
173-
* @param string $time
174-
*
175-
* @return bool
176-
*/
177-
public function setPaidAt(string $time = 'now'): bool;
178-
179-
/**
180-
* Set extra values of the transaction. Every key/value pair that you want to bind to the transaction
181-
*
182-
* @param string $key
183-
* @param $value
184-
* @param bool $save
185-
*
186-
* @return bool
187-
*/
188-
public function setExtra(string $key, $value, bool $save = true): bool;
189-
190-
/**
191-
* Set callback parameters from payment gateway
192-
*
193-
* @param array $paramaetrs
194-
* @param bool $save
195-
*
196-
* @return bool
197-
*/
198-
public function setCallBackParameters(array $parameters, bool $save = true): bool;
199-
}
62+
63+
namespace Tartan\Larapay\Transaction;
64+
65+
interface TransactionInterface
66+
{
67+
/**
68+
* set gateway token of transaction
69+
*
70+
* @param string $token
71+
* @param bool $save
72+
*
73+
* @return mixed
74+
*/
75+
public function setGatewayToken(string $token, bool $save = true): bool;
76+
77+
/**
78+
* set reference ID of transaction
79+
*
80+
* @param string $referenceId
81+
* @param bool $save
82+
*
83+
* @return mixed
84+
*/
85+
public function setReferenceId(string $referenceId, bool $save = true): bool;
86+
87+
/**
88+
* check if transaction is ready for requesting token from payment gateway or not
89+
*
90+
* @return boolean
91+
*/
92+
public function checkForRequestToken(): bool;
93+
94+
/**
95+
* check if transaction is ready for requesting verify method from payment gateway or not
96+
*
97+
* @return bool
98+
*/
99+
public function checkForVerify(): bool;
100+
101+
/**
102+
* check if transaction is ready for requesting inquiry method from payment gateway or not
103+
* This feature does not append to all payment gateways
104+
*
105+
* @return bool
106+
*/
107+
public function checkForInquiry(): bool;
108+
109+
/**
110+
* check if transaction is ready for requesting after verify method from payment gateway or not
111+
* This feature does not append to all payment gateways.
112+
* for example in Mellat gateway this method can assume as SETTLE method
113+
*
114+
* @return bool
115+
*/
116+
public function checkForAfterVerify(): bool;
117+
118+
/**
119+
* check if transaction is ready for requesting refund method from payment gateway or not
120+
* This feature does not append to all payment gateways
121+
*
122+
* @return bool
123+
*/
124+
public function checkForRefund(): bool;
125+
126+
/**
127+
* Set the card number (hash of card number) that used for paying the transaction
128+
* This data does not provide by all payment gateways
129+
*
130+
* @param string $cardNumber
131+
* @param bool $save
132+
*
133+
* @return bool
134+
*/
135+
public function setCardNumber(string $cardNumber, bool $save = true): bool;
136+
137+
/**
138+
* Mark transaction as a verified transaction
139+
*
140+
* @param bool $save
141+
*
142+
* @return bool
143+
*/
144+
public function setVerified(bool $save = true): bool;
145+
146+
/**
147+
* Mark transaction as a after verified transaction
148+
* For example SETTLED in Mellat gateway
149+
*
150+
* @param bool $save
151+
*
152+
* @return bool
153+
*/
154+
public function setAfterVerified(bool $save = true): bool;
155+
156+
/**
157+
* Mark transaction as a paid/successful transaction
158+
*
159+
* @param bool $save
160+
*
161+
* @return bool
162+
*/
163+
public function setAccomplished(bool $save = true): bool;
164+
165+
/**
166+
* Mark transaction as a refunded transaction
167+
*
168+
* @param bool $save
169+
*
170+
* @return bool
171+
*/
172+
public function setRefunded(bool $save = true): bool;
173+
174+
/**
175+
* Returns the payable amount af the transaction
176+
*
177+
* @return int
178+
*/
179+
public function getPayableAmount(): int;
180+
181+
/**
182+
* Set callback parameters from payment gateway
183+
*
184+
* @param array $parameters
185+
* @param bool $save
186+
*
187+
* @return bool
188+
*/
189+
public function setCallBackParameters(array $parameters, bool $save = true): bool;
190+
191+
/**
192+
* Set extra values of the transaction. Every key/value pair that you want to bind to the transaction
193+
*
194+
* @param string $key
195+
* @param $value
196+
* @param bool $save
197+
*
198+
* @return bool
199+
*/
200+
public function setExtra(string $key, $value, bool $save = true): bool;
201+
}
200202

201203

202204
```
203205

204206
6. Prepare for online payment
205207

206208
```php
209+
<?php
210+
211+
// your Laravel action
207212
public function payOnline (Request $request, Transaction $transaction)
208213
{
209214
// check if the selected payment is active or not from your gateways table
@@ -215,18 +220,10 @@ class Transaction extends Model implements TransactionInterface
215220
return view('gateway.notfound');
216221
}
217222

218-
// get some additional parameters for updating transaction
219-
$parameters = [
220-
'description' => $request->input('by_online_description', ''),
221-
'bank' => $request->input('by_online_gateway'),
222-
];
223-
224-
// update transaction payment method
225-
$transaction = $this->transactionsRepository->setTransactionPaid(
226-
$transaction, TransactionPayment::ONLINE, $parameters
227-
);
228-
229-
// make larapay payment gateway instance
223+
/**
224+
* make larapay payment gateway instance
225+
* example: $paymentGatewayHandler = Larapay::make('saman', $transaction);
226+
**/
230227
$paymentGatewayHandler = Larapay::make($paymentGateway->slug, $transaction);
231228

232229

@@ -247,15 +244,15 @@ class Transaction extends Model implements TransactionInterface
247244
} catch (\Exception $e) {
248245
// could not generate goto gate form
249246
Log::emergency($paymentGateway->slug . ' #' . $e->getCode() . '-' . $e->getMessage());
250-
Session::flash('alert-danger', trans('trans.could_not_create_goto_bank_form', ['gateway' => $paymentGateway->name]));
247+
Session::flash('alert-danger', trans('trans.could_not_create_goto_bank_form', ['gateway' => $paymentGateway->slug]));
251248

252249
return redirect()->back()->withInput();
253250
}
254251
if (is_null($form)) {
255252
return redirect()->back()->withInput();
256253
}
257254

258-
// view goto gate view
255+
// view goto gate form/view
259256
return view('gateway.gotogate', [
260257
'gateway' => $paymentGateway,
261258
'form' => $form,

src/Adapter/AdapterAbstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct(TransactionInterface $transaction, array $configs =
6666
$this->transaction = $transaction;
6767

6868
if ($this->transaction->checkForRequestToken() == false) {
69-
throw new Exception('could not handle this transaction payment');
69+
throw new Exception('Due to checkForRequestToken() result, could not handle this transaction`s payment process');
7070
}
7171

7272
$this->setParameters($configs);
@@ -111,7 +111,7 @@ public function getTransaction(): TransactionInterface
111111
*
112112
* @return $this
113113
*/
114-
public function setParameters(array $parameters = []): self
114+
public function setParameters(array $parameters = []): AdapterInterface
115115
{
116116
foreach ($parameters as $key => $value) {
117117
$this->parameters[$key] = trim($value);

src/Adapter/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface AdapterInterface
88
*
99
* @return AdapterInterface
1010
*/
11-
public function setParameters(array $parameters = []): self;
11+
public function setParameters(array $parameters = []): AdapterInterface;
1212

1313
/**
1414
* @return string

src/Adapter/Pasargad.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function verifyTransaction()
9595
$merchantCode = config('larapay.pasargad.merchantId');
9696
$invoiceNumber = $this->iN;
9797
$invoiceDate = $this->iD;
98-
$amount = $this->getTransaction()->getAmount();
98+
$amount = $this->getTransaction()->getPayableAmount();
9999
$timeStamp = date("Y/m/d H:i:s");
100100

101101
$data = "#" . $merchantCode . "#" . $terminalCode . "#" . $invoiceNumber . "#" . $invoiceDate . "#" . $amount . "#" . $timeStamp . "#";
@@ -155,7 +155,7 @@ protected function reverseTransaction()
155155
$merchantCode = config('larapay.pasargad.merchantId');
156156
$invoiceNumber = $this->iN;
157157
$invoiceDate = $this->iD;
158-
$amount = $this->getTransaction()->getAmount();
158+
$amount = $this->getTransaction()->getPayableAmount();
159159
$timeStamp = date("Y/m/d H:i:s");
160160
$action = 1004; // reverse code
161161

src/Adapter/Saman.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function verifyTransaction()
160160
if (isset($response)) {
161161
Log::info('VerifyTransaction response', ['response' => $response]);
162162

163-
if ($response == $this->getTransaction()->getAmount()) { // check by transaction amount
163+
if ($response == $this->getTransaction()->getPayableAmount()) { // check by transaction amount
164164
$this->getTransaction()->setVerified();
165165

166166
return true;

0 commit comments

Comments
 (0)