Skip to content

Commit

Permalink
change to bodytype json (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed Sep 11, 2023
1 parent 4d11a22 commit b29754f
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace Razorpay\Api;

use Requests;

class Order extends Entity
{
/**
* @param $id Order id description
*/
public function create($attributes = array())
{
$attributes = json_encode($attributes);

Request::addHeader('Content-Type', 'application/json');

return parent::create($attributes);
}

Expand Down
30 changes: 30 additions & 0 deletions tests/CoverageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,34 @@ public function testUtilityCoverage(){
$utility->testPaymentLinkVerification();
$utility->testSubscriptionVerification();
}

/**
* @covers \Razorpay\Api\Order::create
*/
public function testSetHeaderJson()
{
$order = new ExceptionTest();
$order->setup();
$order->testCreateOrderSetHeaderException();
}

/**
* @covers \Razorpay\Api\Order::create
*/
public function testSendJsonPayload()
{
$order = new ExceptionTest();
$order->setup();
$order->testCreateJsonOrderException();
}

/**
* @covers \Razorpay\Api\Order::create
*/
public function testSendArrayPayload()
{
$order = new ExceptionTest();
$order->setup();
$order->testCreateOrderSuccess();
}
}
100 changes: 100 additions & 0 deletions tests/ExceptionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

namespace Razorpay\Tests;

use Razorpay\Api\Request;
use Razorpay\Api\Errors;

class ExceptionTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
}

/**
* Create an order from json payload
*/
public function testCreateJsonOrderException()
{
$payload = $this->payload();
$attribute = json_encode($payload);
try
{
$data = $this->api->order->create($attribute);

$this->assertTrue(is_array($data->toArray()));

}
catch(Error $e){
throw new InvalidArgumentException($e);
}
}

/**
* Create an order from set header application/json
*/
public function testCreateOrderSetHeaderException()
{
$attribute = $this->payload();

try
{
$this->api->setHeader('content-type', 'application/json');

$data = $this->api->order->create($attribute);

$this->assertTrue(is_array($data->toArray()));

}
catch(Error $e){
throw new InvalidArgumentException($e);
}
}

/**
* Create an order
*/
public function testCreateOrderSuccess()
{
$attribute = $this->payload();
try
{
$data = $this->api->order->create($attribute);

$this->assertTrue(is_array($data->toArray()));

}
catch(Error $e){
throw new InvalidArgumentException($e);
}
}

private function payload(){
$date = new \DateTime();
$receiptId = $date->getTimestamp();
return [
"receipt"=> (string) $receiptId,
"amount"=>54900,
"currency"=>"INR",
"payment_capture"=>1,
"app_offer"=>0,
"notes" => [
"woocommerce_order_number" => 240186
],
"line_items_total" => 54900,
"line_items" => [
[
"type" => "e-commerce",
"sku"=> "",
"variant_id" => "211444",
"price" => "54900",
"offer_price" => "54900",
"quantity" => 1,
"name" => "Personalised Kids T-shirts",
"description" => "description"
]
]
];
}
}

0 comments on commit b29754f

Please sign in to comment.