I keep getting the error "Unable to create resource." for vimeo API, how can I fix this? - vimeo-api

Errors:
Warning: file_put_contents(): Only 0 of 207 bytes written, possibly out of free disk space in C:\xampp\htdocs\vimeotest\vendor\ankitpokhrel\tus-php\src\Cache\FileStore.php on line 191
Fatal error: Uncaught Vimeo\Exceptions\VimeoUploadException: Unable to create resource. in C:\xampp\htdocs\vimeotest\vendor\vimeo\vimeo-api\src\Vimeo\Vimeo.php:617
Stack trace:
#0 C:\xampp\htdocs\vimeotest\vendor\vimeo\vimeo-api\src\Vimeo\Vimeo.php(345): Vimeo\Vimeo->perform_upload_tus('C:\Users\ellio\...', 2860896, Array)
#1 C:\xampp\htdocs\vimeotest\index.php(22): Vimeo\Vimeo->upload('C:\Users\ellio\...', Array)
#2 {main}
thrown in C:\xampp\htdocs\vimeotest\vendor\vimeo\vimeo-api\src\Vimeo\Vimeo.php on line 617
Code:
session_start();
require 'vendor/autoload.php';
$client_id = 'myid';
$client_secret = 'my client secret';
$access_token = 'my access token';
use Vimeo\Vimeo;
$client = new Vimeo("$client_id", "$client_secret", "$access_token");
$response = $client->request('/tutorial', array(), 'GET');
echo '<pre>';
print_r($response);
$file_name = 'C:\Users\ellio\Documents\videotest.mp4';
$uri = $client->upload($file_name, array(
"name" => "Untitled",
"description" => "The description goes here."
));
echo "Your video URI is: " . $uri;
$response = $client->request($uri . '?fields=transcode.status');
if ($response['body']['transcode']['status'] === 'complete') {
print 'Your video finished transcoding.';
} elseif ($response['body']['transcode']['status'] === 'in_progress') {
print 'Your video is still transcoding.';
} else {
print 'Your video encountered an error during transcoding.';
}
?>
It uploads a video but it has 0% transcoding completed each time

Related

Unexpected Signature while obtaining user session token

I am using Connecty Cube and following the documentation to get a user session token, however the response is
Client error: POST https://api.connectycube.com/session resulted in a 422 Unprocessable Entity response:
{"errors":["Unexpected signature"]}
I am using the below code to get the session token.
use GuzzleHttp\Psr7;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\TransferException;
$client = new Client();
// Create Connecty Cube Session
$application_id = env('CUBE_APPLICATION_ID');
$auth_key = env('CUBE_APPLICATION_KEY');
$timestamp = time();
$nonce = substr($timestamp, 0, 4);
$response = $client->request('POST', 'https://api.connectycube.com/session', [
'form_params' => [
'application_id' => $application_id,
'auth_key' => $auth_key,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => hash_hmac('sha1',
http_build_query([
'application_id' => $application_id,
'auth_key' => $auth_key,
'nonce' => $nonce,
'timestamp' => $timestamp,
]),
env('CUBE_APPLICATION_SECRET')
),
"user" => [
"email" => <email address>,
"password" => <password>
]
]
]);
$contents = json_decode($response->getBody()->getContents(), true);
var_dump($contents);
Please help me to figure out where I am going wrong. Thank You!
// Application credentials
DEFINE('APPLICATION_ID', 1204);
DEFINE('AUTH_KEY', "HhBrEq4BRgT4R8S");
DEFINE('AUTH_SECRET', "TkpdsDSSWyD6Sgb");
// endpoints
DEFINE('CB_API_ENDPOINT', "https://api.connectycube.com");
DEFINE('CB_PATH_SESSION', "session.json");
// Generate signature
$nonce = rand();
$timestamp = time(); // time() method must return current timestamp in UTC but seems like hi is return timestamp in current time zone
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."&timestamp=".$timestamp;
echo "stringForSignature: " . $signature_string . "<br><br>";
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature
));
// $post_body = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "&timestamp=" . $timestamp . "&nonce=" . $nonce . "&signature=" . $signature;
echo "postBody: " . $post_body . "<br><br>";
// Configure cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, CB_API_ENDPOINT . '/' . CB_PATH_SESSION); // Full path is - https://api.connectycube.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
// Execute request and read responce
$responce = curl_exec($curl);
// Check errors
if ($responce) {
echo $responce . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
echo $error . "\n";
}
// Close connection
curl_close($curl);

How to send push to specific member using SNS topic?

I am using AWS SNS to send a push notification, right now i am using publish method of aws-php-sdk to send push specific device. My requirement is sent push to thousands of members within 30 seconds. When i used publish method it takes 5min to send 1000 users.
I have read about topic it sends multiple members at once, but my scenario is i want to send push to specific users, not all topic users.
For example, i register 10,000 members in one topic, but from this 10,000 some time i am sending 9000, sometimes 1000 members.
So anyone has an idea how to send push using topic but specific members only.
I also think another case, every time i create new topic and register member to this topic and then send a message to him and then delete topic, but here every time when register member it is also taking time. So if you have an idea to register multiple members at once then it will also be helpful for me.
Below is my current code to send push.
$arn = "user arn";
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
$appArn = "application arn";
$sns->publish(array('Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
I would recommend to use publishAsync() method.
$userArnCollection = array(
'arn:XXX',
'arn:YYY',
'arn:ZZZ',
);
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
foreach ($userArnCollection as $userArn) {
$sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $userArn
));
}
EDIT
Example with promise handling
$userArnCollection = array(
'arn:XXX',
'arn:YYY',
'arn:ZZZ',
);
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => my_aws_key,
'secret' => aws_secret,
'region' => region,
'profile' => profile_name,
'debug' => false,
'http' => array('verify' => false)
));
$promises = array();
foreach ($userArnCollection as $userArn) {
$promises[] = $sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \" This is my message \"} }"}',
'MessageStructure' => 'json',
'TargetArn' => $userArn
));
}
$results = \GuzzleHttp\Promise\unwrap($promises);
After trying many solutions i am able to send thousands of notification within one minute, here i am showing code how i do it, I have done with php multicurl functionality, so i execute multiple parallel processes and all process send notification simultaneously.
Define multi curl and prepare URL to send notification
Suppose i have 5,000 members and i have array of it's token and other member details $device_type_ids_arr
I part of all member to 500 bunch, so each time curl execute it sends notification to 500 members
$_datas = array_chunk($device_type_ids_arr, 500);
/*initialise multi curl*/
$mh = curl_multi_init();
$handles = array();
/* Perform loop for each 500 members batch */
foreach ($_datas as $batchPart) {
$ch = curl_init();
$postData['devices'] = $batchPart;
$postData['push_content'] = $push_content;
$data_string = json_encode($postData);
curl_setopt($ch, CURLOPT_URL, base_url() . "EmailPipe/sendNotification/"); //your URL to call amazon service (Explain below)
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: curl/7.39.0');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length:' . strlen($data_string))
);
curl_multi_add_handle($mh, $ch);
$handles[] = $ch;
}
// execute requests and poll periodically until all have completed
$isRunning = null;
do {
curl_multi_exec($mh, $isRunning);
} while ($isRunning > 0);
/* Once all execution are complete remove curl handler */
foreach ($handles as $ch) {
curl_multi_remove_handle($mh, $ch);
}
/* Close multi curl */
curl_multi_close($mh);
Function which is received curl request and send notification
function sendCurlSignal() {
require_once APPPATH . 'libraries/aws-sdk/aws-autoloader.php';
$pipeArr = json_decode(file_get_contents('php://input'), true);
$push_content = $pipeArr["push_content"];
$device_id_arr = $pipeArr["devices"];
$sns = new Aws\Sns\SnsClient(array(
'version' => 'latest',
'key' => "Amazon key",
'secret' => "Amazon secret",
'region' => "region like eu-west-1",
'profile' => "Amazon account user",
'debug' => false,
'http' => array('verify' => false)
));
$appArn = "SNS application arn";
$promises = $results = $retArr = array();
foreach ($device_id_arr as $key => $device_detail) {
$arn = $device_detail['arn']; /* SNS ARN of each device */
$token = $device_detail['token_id']; /* Registered token */
$userid = $device_detail['member_id'];
/* If you don't have arn then add arn for specific token in amazon */
if (empty($arn)) {
try {
$updatedArn = $sns->createPlatformEndpoint(array('PlatformApplicationArn' => $appArn, 'Token' => $token));
$arn = $newArn = isset($updatedArn['EndpointArn']) ? $updatedArn['EndpointArn'] : "";
//update member detail with new arn
if ($newArn != "" && $userid != "" && $token != "") {
/* You can update arn into database for this member */
}
} catch (Exception $e) {
/* Get error if any */
$errorMsg = $e->getMessage();
$newFile = fopen("error_arn_fail.txt", "a+");
fwrite($newFile, "Member Id:" . $userid . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
if (!empty($arn)) {
try {
$promises[$userid] = $sns->publishAsync(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \"' . $push_content . '\" } }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
$promises[$userid]->arn = $arn;
$promises[$userid]->token = $token;
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_async_fail_signal.txt", "a+");
fwrite($newFile, $errorMsg . "\r\n");
fclose($newFile);
}
}
}
/* Broadcast push notification */
$results = \GuzzleHttp\Promise\settle($promises)->wait(TRUE);
/* if you want to get result of broadcast and sent message id then do following */
foreach ($results as $key => $value) {
if (isset($value['reason'])) {
/* Reason come in case of fail */
$message = $value['reason']->getMessage();
$token = (isset($promises[$key]->token)) ? $promises[$key]->token : "";
$arn = (isset($promises[$key]->arn)) ? $promises[$key]->arn : "";
if (empty($arn) || empty($token) || empty($key)) {
$newFile = fopen("error_empty_detail_result.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nArn:" . $arn . "\r\nToken:" . $token . "\r\n");
fclose($newFile);
}
/* Handle error */
if (strpos($message, "Endpoint is disabled") !== false && $token != "" && $arn != "") {
try {
$res = $sns->setEndpointAttributes(array(
'Attributes' => array("Token" => $token, "Enabled" => "true"),
'EndpointArn' => $arn
));
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_endpoint_disable.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nArn:" . $arn . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
if (strpos($message, "No endpoint found for the target arn specified") !== false && $token != "") {
try {
$updatedArn = $sns->createPlatformEndpoint(array('PlatformApplicationArn' => $appArn, 'Token' => $token));
$arn = $newArn = isset($updatedArn['EndpointArn']) ? $updatedArn['EndpointArn'] : "";
//update member detail with new arn
if ($newArn != "" && !empty($key) && $token != "") {
/* You can update arn into database for this member */
}
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_arn_fail.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
/* After handle error resed notification to this users */
if (!empty($arn)) {
try {
$publishRes = $sns->publish(array(
'Message' => '{ "GCM": "{\"data\": { \"message\": \"' . $push_content . '\" } }"}',
'MessageStructure' => 'json',
'TargetArn' => $arn
));
$retArr[$key] = $publishRes->get("MessageId");
} catch (Exception $e) {
$errorMsg = $e->getMessage();
$newFile = fopen("error_push_not_sent.txt", "a+");
fwrite($newFile, "Member Id:" . $key . "\r\nARN:" . $arn . "\r\nToken:" . $token . "\r\n" . $errorMsg . "\r\n");
fclose($newFile);
}
}
} else {
$retArr[$key] = $results[$key]['value']->get("MessageId");
}
}
/* All member data get into one array to perform database operation */
if (isset($retArr) && !empty($retArr)) {
/* in $retArr you get each member amazon message id */
}
}

Batch Insert data into database using web services in yii2 error

I've tried for get data in web services at http://api.rajaongkir.com/dokumentasi/starter. And I was success show data in view browser. When I implementation for insert data with a lot of into database something any wrong. I don't know why.
This code for get data in web service at http://api.rajaongkir.com/dokumentasi/starter. And put in controllers/TestController.php
public function actionGetProvince($id=0)
{
$client = new client();
$addUrl = ($id>0)?'id='.$id:'';
$response = $client->createRequest()
->setFormat(Client::FORMAT_JSON)
->setMethod('get')
->setUrl('http://api.rajaongkir.com/starter/province?'.$addUrl)
->addHeaders(['key' => 'example'])
->send();
if ($response->isOk) {
$content = \Yii\helpers\Json::decode($response->content);
//$content['rajaongkir']['query']
//$content['rajaongkir']['status']
$results = $content['rajaongkir']['results'];
if ($id > 0) {
if (count($results)>0) {
echo $results['province_id'] . ' - ';
echo $results['province'] . '<br>';
}
else {
echo "blank";
}
} else {
foreach ($results as $provinces) {
echo $provinces['province_id']." - ".$provinces['province']."<br>";
}
}
} else {
$content = \Yii\helpers\Json::decode($response->content);
echo $content['rajaongkir']['status']['description'];
}
}
And this code for insert data with a lot of in database, and I put in file same.
Yii::$app->db->createCommand()->batchInsert('province', [
'id_province' => $provinces['province_id'], 'name' => $provinces['province']
])->execute();
And the result error is :
PHP Warning – yii\base\ErrorException : Missing argument 3 for yii\db\Command::batchInsert(), called in C:\wamp\www\basic_yii2\controllers\TestController.php on line 60 and defined
You are not calling batchInsert() properly.
See it in documentation.
public $this batchInsert ( $table, $columns, $rows )
$table string The table that new rows will be inserted into.
$columns array The column names
$rows array The rows to be batch inserted into the table
Example:
$connection->createCommand()->batchInsert('user', ['name', 'age'], [
['Tom', 30],
['Jane', 20],
['Linda', 25],
])->execute();

Fetch product from amazon mws using product api

I have successfully posted product in amazon using amazon MWS Feeds API. Now i want to list those products using the Products API, But im facing some errors.
I run GetMatchingProductSample.php.
Caught Exception: Required parameter ASINList not found Response Status Code: 400 Error Code: MissingParameter Error Type: Sender Request ID: 8bb9c8d1-f48c-495c-be86-89492976b4a9 XML: SenderMissingParameterRequired parameter ASINList not found8bb9c8d1-f48c-495c-be86-89492976b4a9 ResponseHeaderMetadata: RequestId: 8bb9c8d1-f48c-495c-be86-89492976b4a9
Code:
<?php
require_once('.config.inc.php');
$serviceUrl = "https://mws-eu.amazonservices.com/Products/2011-10-01";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceProducts_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
$request = new MarketplaceWebServiceProducts_Model_GetMatchingProductRequest();
$request->setSellerId(MERCHANT_ID);
// object or array of parameters
invokeGetMatchingProduct($service, $request);
function invokeGetMatchingProduct(MarketplaceWebServiceProducts_Interface $service, $request)
{
try {
$response = $service->GetMatchingProduct($request);
echo ("Service Response\n");
echo ("=============================================================================\n");
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
echo $dom->saveXML();
echo("ResponseHeaderMetadata: " . $response->getResponseHeaderMetadata() . "\n");
} catch (MarketplaceWebServiceProducts_Exception $ex) {
echo("Caught Exception: " . $ex->getMessage() . "\n");
echo("Response Status Code: " . $ex->getStatusCode() . "\n");
echo("Error Code: " . $ex->getErrorCode() . "\n");
echo("Error Type: " . $ex->getErrorType() . "\n");
echo("Request ID: " . $ex->getRequestId() . "\n");
echo("XML: " . $ex->getXML() . "\n");
echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
}
}
As it says ASINList not found
You need to add these line of code after below line
$request->setSellerId(MERCHANT_ID);
Code needs to add:
$request->setMarketplaceId($marketplace_id);
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asins = array("ASIN1","ASIN2","ASIN3");
$asin_list->setASIN($asins);
$request->setASINList($asin_list);

Coupon Magento API Soap

I’ve a problem with the Coupon API when i make :
$couponCode = "test";
$resultCartCoupon = $proxy->call($sessionId, "cart_coupon.add", array($shoppingCartId, $couponCode));
I always got : Uncaught SoapFault exception: [1083] Coupon is not valid if i try the coupon code in the front end there is no problem. Is there anyone who have ever used this API part with success ?
Thanks.
This error comes from Mage_Checkout_Model_Cart_Coupon_Api::_applyCoupon()
if ($couponCode) {
if (!$couponCode == $quote->getCouponCode()) {
$this->_fault('coupon_code_is_not_valid');
}
}
This looks like it could be a bug, instead it should be if ($couponCode != $quote->getCouponCode()) { but I'm not certain.
It could be that the cart (quote) you're trying to apply the coupon to isn't valid, i.e. doesn't have the qualifying items it needs to receive the coupon. Are you sure $shoppingCartId correctly matches the expected quote in Magento's sales_flat_quote table?
I noticed that the error is in this excerpt:
try {
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->setCouponCode(strlen($couponCode) ? $couponCode : '')
->collectTotals()
->save();
} catch (Exception $e) {
$this->_fault("cannot_apply_coupon_code", $e->getMessage());
}
In this specific line: ->collectTotals() By removing this stretch , not of error , but not applied the coupon.
After debugging 2-3 hour on API, I have solved this error at my-end. Check below code which i have used in Coupon API.
<?php
$mage_url = 'http://yoursiteurl/api/soap?wsdl';
$mage_user= "API_User"; //webservice user login
$mage_api_key = "API_PASSWORD"; //webservice user pass
$client = new SoapClient($mage_url);
$couponCode = 'couponCode'; // a coupon to be apply
$shoppingCartId = '35'; // a cart Id which i have put test id
$sessionId = $client->login($mage_user, $mage_api_key);
$result = $client->call($sessionId,'cart_coupon.add',array($shoppingCartId,$couponCode));
print_r($result);
?>
The above code gives error that "Uncaught SoapFault exception: [1083] Coupon is not valid". When i debugg the core code i came to know that magento cart.create API insert wrong store id in sales_flat_quote table. I have changed the store id value in sales_flat_quote table manually and again run the Coupon API and after that it works perfectly. So here is the my solution. When you create cart id just run the below update query to change the store id.
<?php
$shoppingCartId = $soap->call( $sessionId, 'cart.create');
$mageFilename = '../app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
$db_write1 = Mage::getSingleton('core/resource')->getConnection('core_write');
$updateQue = "update sales_flat_quote set store_id='1' where entity_id ='".$shoppingCartId."'";
$db_write1->query($updateQue);
// Now run the Coupon API here
?>
Code taken from here : http://chandreshrana.blogspot.in/2015/11/uncaught-soapfault-exception-1083.html
You do not need to write direct SQL to resolve this issue. Just specify store ID parameter in the API call. Example is below is the demo script to apply discount code using Magento SOAP APIs V2 :
/* Set Discount Code */
try
{
$result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
echo "<br>Apply discount code: ";
var_dump($result);
}
catch(Exception $ex)
{
echo "<br>Discount code Failed: " . $ex->getMessage();
}
To apply discount code, perform following steps :
$quoteId = $client->shoppingCartCreate($session,$storeId);
/* Set cart customer */
$guest = true;
if ($guest)
{
$customerData = array(
"firstname" => "testFirstname",
"lastname" => "testLastName",
"email" => "testEmail#mail.com",
"mode" => "guest",
"website_id" => "1"
);
}
else
{
$customer = array(
"customer_id" => '69301',
"website_id" => "1",
"group_id" => "1",
"store_id" => "1",
"mode" => "customer",
);
}
//Set cart customer (assign customer to quote)
$resultCustomerSet = $client->shoppingCartCustomerSet($session, $quoteId, $customerData,$storeId);
/* Set customer addresses Shipping and Billing */
$addresses = array(
array(
"mode" => "shipping",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
),
array(
"mode" => "billing",
"firstname" => "Ahsan",
"lastname" => "testLastname",
"company" => "testCompany",
"street" => "testStreet",
"city" => "Karachi",
"region" => "Sindh",
"postcode" => "7502",
"country_id" => "PK",
"telephone" => "0123456789",
"fax" => "0123456789",
"is_default_shipping" => 0,
"is_default_billing" => 0
)
);
//Set cart customer address
$resultCustomerAddress = $client->shoppingCartCustomerAddresses($session, $quoteId, $addresses,$storeId);
/* Set payment method */
$responsePayment = $client->shoppingCartPaymentMethod($session, $quoteId, array(
'method' => 'cashondelivery',
),$storeId);
/* Set shipping method */
$setShipping = $client->shoppingCartShippingMethod($session, $quoteId, 'flatrate_flatrate',$storeId);
After all above apply discount code,
try
{
$result = $client->shoppingCartCouponAdd($session, $quoteId, 'test123',$storeId);
echo "<br>Apply discount code: ";
var_dump($result);
}
catch(Exception $ex)
{
echo "<br>Discount code Failed: " . $ex->getMessage();
}