I am using PHP and have a webhook generated with invoice.created. When the invoice is created, Stripe lets the draft invoice sit there for about an hour which gives us time to edit the invoice or adjust it. I use this time to check the database (via webhook) to see how many referrals this person has in the system to the adjust the coupons accordingly. I can't seem to adjust the invoice properly as I get errors in all the ways I have tried, which are:
$inv = {the invoice id and I get no error from the invoice ID being incorrect
define('STRIPE_API_KEY', 'sk_test_******************');
$stripe = new \Stripe\StripeClient(
STRIPE_API_KEY
);
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
Error is unknown object discounts.coupon
and
$stripe->invoices->update(
$inv,
['discount' => '20OFF']
);
Error = Fatal error: Uncaught (Status 400) (Request req_hsX1QTOxzWMiQn) Received unknown parameter: discount. Did you mean discounts? thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
and
$stripe->invoices->update(
$inv,
['coupon' => '20OFF']
);
ERROR = Fatal error: Uncaught (Status 400) (Request req_yEwwOLoukR6j6Z) Received unknown parameter: coupon thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => '20OFF']]
);
Fatal error: Uncaught (Status 400) (Request req_IDRP1Rjv1YoBZR) Invalid array thrown in /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php on line 38
I'm pretty sure I need to use 'discounts' but don't know how to structure the array to pass the coupon properly.
Trying to predict some questions or comments:
Yes, I do have an existing coupon with id of 20OFF. This is for 20% off
$inv does fetch the correct ID of the invoice at the time the webhook is sent.
Here is the link of the API documentation that I've been reading, but it isn't very helpful.
Instead of:
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
try:
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => $couponId]]
);
It looks like it must be the id of the coupon and not the customer facing code, e.g. 20OFF.
You would be able to get the id of the coupon from the dashboard (https://dashboard.stripe.com/coupons/) or by making another api request.
It's
$stripe->invoices->update(
$inv,
[
'discounts' => [
['coupon' => '20OFF']
]
]
);
As in, it's an array that then contains objects (in PHP those are both square brackets) and the objects refer to the coupon.
Related
i would like to refund a payment on a connected account. Therefore I'm using the following code:
$acc = \Stripe\Account::retrieve($conn_account);
$ch_id = "ch_XXXXXXXXXXXXX";
/*$ch = $stripe->charges->capture(
$ch_id,
[],
['stripe_account' => $conn_account ]
);
echo $ch;
*/
$stripe->refunds->create([
'charge' => $ch_id,
]);
Running the pgp returns
Fatal error: Uncaught (Status 404) (Request req_XXXXXXXX) No such charge: 'ch_XXXXXXXXXXXXXXXXXXX'
thrown in C:\xampp\htdocs\user\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php on line 38<br /
How can I solve this?
Thanks!
Did you created the charge by setting Stripe-Account header to your connected account ID? If so, you need to also set the Stripe-Account header when creating your refund. Your code should look like this:
$stripe->refunds->create(
['charge' => $ch_id ],
['stripe_account' => $conn_account ]
);
You can take a look at the documentation for more information (like refunding application fees): https://stripe.com/docs/connect/direct-charges#issuing-refunds
I am trying to implement the Stripe PHP API, but I am stuck since last week.
At first I thought I did not mention the payment method correctly in the way of a correct notation.
However this seems not to be the case.
I have created a wrapper class that loads all stripe API files and following handles all calls required for me.
Hence that's why the code layout.
When I execute my script I receive the following error :
Fatal error: Uncaught (Status 400) (Request req_AQbkjKFB4mo31Z) You
cannot confirm this PaymentIntent because it's missing a payment
method. You can either update the PaymentIntent with a payment method
and then confirm it again, or confirm it again directly with a payment
method. thrown in
httpdocs/stripe/stripe/lib/Exception/ApiErrorException.php
on line 38
I have contacted the Stripe helpdesk already however they keep referring me to their manual but that doesn't get me any further either.
The iDeal payment method has been enabled in their dashboard. So that's not the reason for failure.
Where it COULD be is the manner I setup my payment. But for as far as I am concerned I do not have set the payment method correctly. But for as far as I can see that has been done accordingly their manual.
Also, I cannot find any confirmatory documentation about using the retrieve call. Should I do this? Or is this simply double and unneeded.
public function create_payment($amount, $order_id, $method = 'ideal', $return_url = NULL, $currency = 'eur'){
///######## CHECK IF CURRENCY IS ALLOWED
if(!$this->currency_supported($currency)) exit('<strong>error</strong>, stripe currency not supported : '.$currency);
///######## SETUP PAYMENT
$result = $this->obj->paymentIntents->create(
array(
'amount' => $amount,
'currency' => $currency,
'payment_method_types' => array($method)
)
);
///######## IF ERROR
if(!is_object($result) || !isset($result->id)) exit('<strong>error</strong>, something went wrong during stripe payment intend creation');
///######## SETUP PAYMENT ID
$payment_id = $result->id;
///######## RETRIEVE PAYMENT INTEND DETAILS
$result = $this->obj->paymentIntents->retrieve($payment_id, []);
///######## SET AN ORDER ID
$result = $this->obj->paymentIntents->update($payment_id, array(
'metadata' => array(
'order_id' => $order_id,
),
'payment_method_types' => array($method),
));
///######## SETUP PARAMETRES
$params = array('payment_method_types' => array($method));
///######## IF THE RETURN URL HAS BEEN SET
if($return_url) $params['return_url'] = $return_url;
///######## CONFIRM A PAYMENT INTEND
$result = $this->obj->paymentIntents->confirm($payment_id, $params);
exit(print_r($result));
}
I hope that one could point me at my error. Since I am absolutely stuck here.
I am trying to Create an item in the podio API for PHP. Here is my code:
Podio::setup($client_id, $client_secret);
Podio::authenticate_with_app($app_id, $app_token);
// Create a field collection with some fields.
// Be sure to use the external_ids of your specific fields
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id"=>"first", "values"=> "Han")),
new PodioTextItemField(array("external_id"=>"last", "values"=> "Solo"))
));
// Create the item object with fields
// Be sure to add an app or podio-php won't know where to create the item
$item = new PodioItem(array(
'app' => new PodioApp($app_id), // Attach to app with app_id=$app_id
'fields' => $fields
));
// Save the new item
$item->save();
But I get error
Notice: Undefined index: request in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\lib\PodioError.php on line 11
Fatal error: Uncaught PodioMissingRelationshipError: "Item is missing
relationship to app" Request URL: Stack Trace: #0 C:\xampp\htdocs\PodioAPITesting\testPodioAPI.php(66): PodioItem->save() #1 {main} thrown in C:\xampp\htdocs\PodioAPITesting\vendor\podio\podio-php\models\PodioItem.php on line 75
Am I creating the item properly? Could it be because this app has more that two fields? ( I want to set 'first' and 'last', and leave the other fields blank for now)
The problem was that my $app_id was a string when it should have been an integer.
I want to delete an event in Vtiger Calendar using REST APIs. I'm trying the following:
POST /webservice.php HTTP/1.1
operation=delete
sessionName=sessionId // Obtained through Login Operation
id=<WEBSERVICE_ID>
but I don't know what WEBSERVICE_ID is and where to find it.
When I create an event using REST-API it returns an array with the following data:
{"subject":"Follow up Test","assigned_user_id":"49x1","date_start":"2016-06-17","time_start":"09:00:00","time_end":"18:00:00","due_date":"2016-06-17","recurringtype":"","parent_id":"","contact_id":"","taskstatus":"","eventstatus":"Planned","taskpriority":"High","sendnotification":"0","createdtime":"2016-06-23 11:18:20","modifiedtime":"2016-06-23 11:18:20","activitytype":"Event","visibility":"","duration_hours":"9","duration_minutes":"0","location":"","notime":"0","modifiedby":"49x1","created_user_id":"49x1","source":"WEBSERVICE","starred":"0","tags":"","reminder_time":"","description":"Test Description","id":"1x5748","label":"Follow up Test"}
There is an id in the array ("id":"1x5748"), but when I try to use the id as a WEBSERVICE_ID in the delete operation I'm getting the following error:
Fatal error: Uncaught exception 'Exception' with message 'Error: Id specified is incorrect'
Run this query: SELECT id, nameFROM vtiger_ws_entity
Whith this your objectTypeId is a id for module
Get the record id
concatenate 1And2 for example: EVENTS module='18' AND record id=61900, then the ID that you need is: 18x61900;
I use this code for delete entity
$params = array(
//"id" => "35789",
"id" => "18x61900",
);
$record = $client->doInvoke("delete", $params, "POST");
I am trying to use the Magento API to UPDATE a product. I am getting error code #1 with the following message:<b>Fatal error</b>: Uncaught SoapFault exception: [1] Internal Error. Please see log for details.
Below is my PHP that calls the service and should update three attributes. The Magento api documentation leaves a lot to the imagination so I am stuck
$ItemNmbr = $itemData->Item->ItemNmbr;
$ItemDesc = $itemData->Item->ItemDesc;
$UnitPrce = $itemData->Item->UnitPrce;
$client = new SoapClient('http://website.com/store/api/?wsdl');
$session = $client->login('apiname', 'apipassword');
$result = $client->call($session, 'catalog_product.update', array(168, array(
'description' => $ItemDesc,
'price' => $UnitPrce,
'weight' => $Weight
)));
var_dump ($result);
I am statically setting the ProductID above for now. Any information that will help me understand what I am doing wrong would be much appreciated.