/** * */ public function testSaleAndRefund() { $client = new Client($this->clientId, $this->secretKey); $randomOrderId = rand(1000, 10000); // first lets create a sale $saleRequest = $client->createRequest('Sale'); $saleRequest->setFname('Gassan')->setLname('Idriss')->setEmail('*****@*****.**')->setPhoneNumber('6192920984')->setUserId('455')->setOrderId($randomOrderId)->setTimestamp(new \DateTime('now')); $saleRequest->setBillingAddress(new Address('940 W San Marcos Blvd', 'Std D', 'San Marcos', 'CA', '92078', 'US')); foreach ($this->testItems as $testItem) { $saleRequest->addLineItem(new LineItem($testItem, 29.99)); } $saleResponse = $client->doRequest($saleRequest); $this->assertTrue($saleResponse->isSuccess()); // now refund it $refundRequest = $client->createRequest('Refund'); $refundRequest->setOrderId($randomOrderId)->setTimestamp(new \DateTime('now')); foreach ($this->testItems as $testItem) { $refundRequest->addLineItem(new LineItem($testItem, 29.99)); } $refundResponse = $client->doRequest($refundRequest); $this->assertTrue($refundResponse->isSuccess()); }
/** * */ public function testRequest() { // test a sale request with a randomly generated request $client = new Client($this->clientId, $this->secretKey); $request = $client->createRequest('SaleRequest'); // mock order $mockOrder = static::createMockOrder(); $request->setFname($mockOrder['fname'])->setLname($mockOrder['lname'])->setEmail($mockOrder['email'])->setPhoneNumber($mockOrder['phone_number'])->setUserId($mockOrder['user_id'])->setOrderId($mockOrder['order_id'])->setTimestamp($mockOrder['timestamp']); $billingAddress = new Address($mockOrder['billing_address']['address'], $mockOrder['billing_address']['address2'], $mockOrder['billing_address']['city'], $mockOrder['billing_address']['state'], $mockOrder['billing_address']['zip'], $mockOrder['billing_address']['country']); $request->setBillingAddress($billingAddress); if (isset($mockOrder['shipping_address']) && count($mockOrder['shipping_address'])) { $shippingAddress = new Address($mockOrder['shipping_address']['address'], $mockOrder['shipping_address']['address2'], $mockOrder['shipping_address']['city'], $mockOrder['shipping_address']['state'], $mockOrder['shipping_address']['zip'], $mockOrder['shipping_address']['country']); $request->setShippingAddress($shippingAddress); } if (isset($mockOrder['products']) && count($mockOrder['products'])) { foreach ($mockOrder['products'] as $sku) { $request->addProduct(new Product($sku)); } } if (isset($mockOrder['line_items']) && count($mockOrder['line_items'])) { foreach ($mockOrder['line_items'] as $lineItem) { $request->addLineItem(new LineItem($lineItem['sku'], $lineItem['price'])); } } $response = $client->doRequest($request); $this->assertTrue($response->isSuccess()); }