Skip to content

Commit 475c889

Browse files
ionutcalaratjconcept
authored andcommitted
Updated request structure to send objects via curl
1 parent ed633c3 commit 475c889

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

Paylike/Adapter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ public function request( $url, $data = null, $httpVerb = 'post' ) {
5252
$ch = curl_init();
5353
curl_setopt( $ch, CURLOPT_URL, $url );
5454
curl_setopt( $ch, CURLOPT_HEADER, false );
55+
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
56+
'Accept: application/json',
57+
'Content-Type: application/json'
58+
) );
5559
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
5660
curl_setopt( $ch, CURLOPT_USERPWD, ":" . $this->apiKey );
5761
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
5862
switch ( $httpVerb ) {
5963
case 'post':
6064
curl_setopt( $ch, CURLOPT_POST, true );
6165
if ( $data ) {
62-
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
66+
$encoded = json_encode($data);
67+
curl_setopt( $ch, CURLOPT_POSTFIELDS, $encoded );
6368
}
6469
break;
6570
case 'get':

Paylike/Transaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function fetch( $transactionId ) {
4444
trigger_error( 'Adapter not set!', E_USER_ERROR );
4545
}
4646

47-
return $adapter->request( 'transactions/' . $transactionId );
47+
return $adapter->request( 'transactions/' . $transactionId, $data = null, $httpVerb = 'get' );
4848
}
4949

5050
/**

examples.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@
2727
break;
2828
case "createTransaction":
2929
$transaction = \Paylike\Transaction::fetch( $transactionId );
30-
$merchantId = $transaction['merchantId'];
30+
$merchantId = $transaction['transaction']['merchantId'];
3131
$data = array(
32-
'amount' => $amount,
33-
'currency' => $currency
32+
'transactionId' => $transactionId,
33+
'amount' => $amount,
34+
'currency' => $currency,
35+
'custom' => array(
36+
'email' => 'ionut@derikon.com'
37+
)
3438
);
3539
$response = \Paylike\Transaction::create( $merchantId, $data );
3640
break;
@@ -104,7 +108,7 @@
104108
echo '<div style="color:#fe171d">Card operation failed.</div>';
105109
}
106110
} else {
107-
if ( isset( $response['transaction']['successful'] ) && $response['transaction']['successful'] ) {
111+
if ( isset( $response['transaction']['id'] ) && $response['transaction']['id'] ) {
108112
echo '<div style="color:rgb(69, 110, 16)">Transaction operation was successful.</div>';
109113
} else {
110114
echo '<div style="color:#fe171d">Transaction operation failed.</div>';

0 commit comments

Comments
 (0)