Skip to content

Commit 563947c

Browse files
committed
add apple pay
1 parent 4b7ff72 commit 563947c

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

config/hyperpay.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
'entityIdMada' => env('ENTITY_ID_MADA'),
77

8+
'entityIdApplePay' => env('ENTITY_ID_APPLE_PAY'),
9+
810
'entityId' => env('ENTITY_ID'),
911

1012
'access_token' => env('ACCESS_TOKEN'),

src/LaravelHyperpay.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,24 @@ public function __construct(GuzzleClient $client)
6363
}
6464

6565
/**
66-
* Set the mada entityId in the paramaters that used to prepare the checkout.
66+
* Set the mada entityId in the parameters that used to prepare the checkout.
6767
*
6868
* @return void
6969
*/
7070
public function mada()
7171
{
7272
$this->config['entityId'] = config('hyperpay.entityIdMada');
7373
}
74-
74+
75+
/**
76+
* Set the apple pay entityId in the parameters that used to prepare the checkout.
77+
*
78+
* @return void
79+
*/
80+
public function setApplePayEntityId()
81+
{
82+
$this->config['entityId'] = config('hyperpay.entityIdApplePay');
83+
}
7584
/**
7685
* Add billing data to the payment body.
7786
*
@@ -103,6 +112,10 @@ public function checkout(array $trackable_data, Model $user, $amount, $brand, Re
103112
if (strtolower($this->brand) == 'mada') {
104113
$this->mada();
105114
}
115+
116+
if (strtolower($this->brand) == 'applepay') {
117+
$this->setApplePayEntityId();
118+
}
106119

107120
$trackable_data = array_merge($trackable_data, [
108121
'amount' => $amount,

src/Support/HttpParameters.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,17 @@ protected function getBillingParameters($billing): array
9797
protected function getEntityId($id)
9898
{
9999
$transaction = (new TransactionBuilder())->findByIdOrCheckoutId($id);
100+
100101
$entityId = config('hyperpay.entityId');
102+
101103
if ($transaction->brand === 'mada') {
102104
$entityId = config('hyperpay.entityIdMada');
103105
}
104106

107+
if ($transaction->brand === 'applepay') {
108+
$entityId = config('hyperpay.entityIdApplePay');
109+
}
110+
105111
return $entityId;
106112
}
107113
}

src/Support/TransactionBuilder.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct($owner = null)
3333
*/
3434
public function create(array $transactionData)
3535
{
36-
$this->currentUserCleanOldPendingTransaction();
36+
$this->currentUserCleanOldPendingTransaction($transactionData);
3737

3838
$transaction = $this->owner->transactions()->create([
3939
'id' => Arr::get($transactionData, 'merchantTransactionId'),
@@ -81,6 +81,10 @@ protected function getBrand($entityId)
8181
return 'mada';
8282
}
8383

84+
if ($entityId == config('hyperpay.entityIdApplePay')) {
85+
return 'applepay';
86+
}
87+
8488
return 'default';
8589
}
8690

@@ -89,9 +93,9 @@ protected function getBrand($entityId)
8993
*
9094
* @return void
9195
*/
92-
protected function currentUserCleanOldPendingTransaction()
96+
protected function currentUserCleanOldPendingTransaction(array $transactionData)
9397
{
94-
$transaction = $this->owner->transactions()->where('status', 'pending')->first();
98+
$transaction = $this->owner->transactions()->where('status', 'pending')->whereBrand($this->getBrand($transactionData['entityId']))->first();
9599
if ($transaction) {
96100
$transaction->delete();
97101
}

0 commit comments

Comments
 (0)