Skip to content

Commit 6d7a6d6

Browse files
authored
Merge pull request #24 from jeffreyzant/master
Send (type redirect) REST request with items #14
2 parents 9c08690 + 0892f58 commit 6d7a6d6

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/Message/RestPurchaseRequest.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ public function setGoogleAnalyticsCode($value)
383383
return $this->setParameter('google_analytics', $value);
384384
}
385385

386+
/**
387+
* Get items HTML
388+
*
389+
* @return string
390+
*/
391+
public function setItemsHtml($itemsHtml)
392+
{
393+
$this->setParameter('itemsHtml', $itemsHtml);
394+
}
395+
396+
/**
397+
* Get items HTML
398+
*
399+
* @return string
400+
*/
401+
public function getItemsHtml()
402+
{
403+
return $this->getParameter('itemsHtml');
404+
}
405+
386406
/**
387407
* Get the payment options.
388408
*
@@ -452,6 +472,29 @@ protected function getGatewayData()
452472
return array_filter($data);
453473
}
454474

475+
/**
476+
* Get itembag data.
477+
*
478+
* @return array
479+
*/
480+
protected function getItemBagData()
481+
{
482+
$items = array();
483+
$itemBag = $this->getItems();
484+
if (! empty($itemBag)) {
485+
foreach ($itemBag->all() as $item) {
486+
$items[] = array(
487+
'name' => $item->getName(),
488+
'description' => $item->getDescription(),
489+
'quantity' => $item->getQuantity(),
490+
'unit_price' => $item->getPrice(),
491+
);
492+
}
493+
}
494+
495+
return $items;
496+
}
497+
455498
/**
456499
* Get the raw data array for this message. The format of this varies from gateway to
457500
* gateway, but will usually be either an associative array, or a SimpleXMLElement.
@@ -492,7 +535,7 @@ public function getData()
492535
'description' => $this->getDescription(),
493536
'gateway' => $this->getGateway(),
494537
'google_analytics' => $this->getGoogleAnalyticsCode(),
495-
'items' => $this->getItems(),
538+
'items' => $this->getItemsHtml(),
496539
'manual' => $this->getManual(),
497540
'order_id' => $this->getTransactionId(),
498541
'recurring_id' => $this->getRecurringId(),
@@ -520,6 +563,12 @@ public function getData()
520563
$data['gateway_info'] = $gatewayData;
521564
}
522565

566+
$getItemBagData = $this->getItemBagData();
567+
568+
if (! empty($getItemBagData)) {
569+
$data['shopping_cart']['items'] = $getItemBagData;
570+
}
571+
523572
return array_filter($data);
524573
}
525574

0 commit comments

Comments
 (0)