Skip to content

Commit

Permalink
access callback response as objects
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbobby committed Oct 16, 2016
1 parent af38038 commit 78ef0ae
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Interswitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function raw(array $options = [])
);

$inputs['txn_ref'] = $this->setTxnRef(
array_get($options, 'txn_ref', TransRef::getHashedToken(7))
array_get($options, 'txn_ref', TransRef::getHashedToken(11))
);

$hashValues = $this->txnref.
Expand All @@ -98,6 +98,10 @@ public function raw(array $options = [])
$inputs['cust_name'] = $this->setCustName(array_get($options, 'cust_name'));
$inputs['cust_id'] = $this->txnref;

foreach ($inputs as $key => $value) {
$this->$key = $value;
}

return $inputs;
}

Expand All @@ -108,20 +112,23 @@ public function raw(array $options = [])
*
* @return HTML
*/
public function form(array $options = [])
public function form(array $options = [], string $id, $submitBtn = true)
{
$array = $this->raw($options);

$action = array_get($array, 'action');

$form = '<form action ="'.$action.'" method="post">'.PHP_EOL;
$form = '<form action ="'.$action.'" method="post" id="'.$id.'">'.PHP_EOL;
$array = array_except($array, ['action']);

foreach ($array as $key => $value) {
$form .= '<input type="hidden" name="'.$key.'" value="'.$value.'" />'.PHP_EOL;
}

$form .= '<input class="submit" type="submit" name="submit" value="Pay" />'.PHP_EOL;
if ($submitBtn) {
$form .= '<input class="submit" type="submit" name="submit" value="Pay" />'.PHP_EOL;
}

$form .= '</form>'.PHP_EOL;

return $form;
Expand All @@ -138,8 +145,13 @@ public function callback()
{
$array = request()->all();
$query = $this->query($array);
$json = json_decode($query, true);

foreach ($json as $key => $value) {
$this->$key = $value;
}

return json_decode($query, true);
return $this;
}

/**
Expand Down

0 comments on commit 78ef0ae

Please sign in to comment.