I created Stripe products, and prices and added payment links to each of them. I am going to use these Payment Links in the future, show them on the site, etc. The PHP backend pulls products, prices, and payment links and shows a pretty formatted picture for the user.
I successfully get products and prices. I didn't find how the PaymentLink API can seek payment links by the price ID. I looked inside the Stripe dashboard and found that it requests payment links in the following way.
https://dashboard.stripe.com/v1/payment_links?include_only[]=data.id&price=price_1MWn4sEnbft6LZBGeHuaLVwf&active=true&limit=2
You can see that it passes the "price" parameter. In the same way, I want to find payment links.
My code
<?php
require_once __DIR__.'/../vendor/autoload.php';
$data = [];// Collected data
$stripe
= new \Stripe\StripeClient('sk_test_');
$products = $stripe->products->all([
'active' => true,
'limit' => 100
]);
foreach ($products as $product) {
$prices = $stripe->prices->all([
'active' => true,
'product' => $product->id,
'limit' => 100,
]);
foreach ($prices as $price) {
$payment_links = $stripe->paymentLinks->all([
'limit' => 100,
// Stripe doesn't have such an option.
//'price' => $price->id
]);
}
// Put found info into the $data var
}
print_r($data);
There is no direct way of searching for PaymentLinks with a certain price ID as you mentioned. The only way is to retrieve a Payment Link's line_items and search whether an item contains the price you're searching for.
Related
I am trying to track customer checkout and purchase through "TheIconic\Tracking\GoogleAnalytics" using shopify google hook. I set up webhook on shopify end so when a customer checkout and purchase it will call particular php script(checkout.php and purchase.php). I was curious if I set up this script in the seperate php file how google analytics knows the same person checkout and purchase products.
$analytics
->setProtocolVersion('1')
->setTrackingId('UA-25099702-3')
->setClientId($productList -> token);
foreach( $productList -> line_items as $item ){ $product = [
'sku' => $item -> sku, 'variant' => $item -> variant_id, 'name' => $item -> title, 'price' => $item -> price, 'quantity' => $item -> quantity, ]; $analytics->addProduct($product); } // Don't forget to set the product action, in this case to PURCHASE
$analytics->setProductActionToCheckout();
// Finally, you must send a hit, in this case we send an Event
$analytics
->setEventCategory('Checkout')
->setEventAction('Checkout')
->sendEvent();
$analytics->sendPageview();
I have an existing customer in Stripe and we plan to add a subscription to the customer. First I want to add an invoice item so the subscription picks it up when created and adds it to the pending invoice. The code below is run in order, however, the invoice item in stripe is shown as paid immediately as opposed to added to the pending invoice on the subscription. The docs say I have it correct as far as I can tell, any idea why the invoice item is not added to the pending invoice?
try {
\Stripe\InvoiceItem::create(
array(
"customer" => $customer['stripe_customer_id'],
"amount" => $invoice_item_amount,
"currency" => "usd",
"description" => $product['description']
)
);
} catch(Error $e) {
// do something
}
try {
$result = $stripe_customerObj->subscriptions->create(
array(
"coupon" => $coupon,
"plan" => $plan_id,
"quantity" => $quantity,
"trial_end" => $trial_end_timestamp,
"metadata" => $metadata
)
);
} catch(Error $e) {
// do something
}
It worked when I moved the InvoiceItem::create to after the creation of the subscription.
This is expected behaviour. The code you have creates an invoice item and then a subscription with a trial. That trial creates a $0 invoice that automatically picks up the invoice item(s) pending including the one you just created. This is the flow you'd use if you wanted to charge a fee for a trial period for example.
If you want the pending invoice item added to the next invoice, you'd create it after the subscription instead.
I am trying to update the tracking number of an order in Bigcommerce using the API. This is the code I am using:
//update BC of order status
$filter = array('status_id' => 2);
$order_status_update = BigCommerce::updateResource('/orders/' . 105, $filter);
$order = Bigcommerce::getOrder(105);
foreach($order->products as $shipment)
{
$filter = array(
'order_address_id' => $shipment->order_address_id,
'items'=> array(
'order_product_id' => $shipment->product_id,
'quantity' => $shipment->quantity
),
'tracking_number' => 'tracking number'
);
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);
}
I have followed the instructions from here:
https://developer.bigcommerce.com/api/stores/v2/orders/shipments#list-shipments
BigCommerce Uploading Tracking Numbers
But I can't seem to get it to work. Can someone help?
In advance, thanks for your help!
Akshay
The payload for creating a shipment is invalid due to the items field needing to be formatted as an object array and the use of the product_id as opposed to the ID of the product within the order.
The code provided is attempting to create one shipment per product in the order, is this intended? Ideally you would ship all items in one shipment, which is why the items field is meant to be an array of product objects.
Additionally, by creating a shipment for an order the order status will automatically change to "Shipped", so the first PUT request is unnecessary.
If you were trying to create a single shipment per order and are assuming no orders will have multiple addresses then this code should work.
$order = Bigcommerce::getOrder(105);
$filter = array(
'order_address_id' => $order->shipping_addresses[0]->id,
'tracking_number' => '123456'
);
foreach($order->products as $product) {
$items[] = array(
'order_product_id' => $product->id,
'quantity' => $product->quantity
);
}
$filter['items'] => $items;
$add_tracking = BigCommerce::createResource('/orders/105/shipments', $filter);
var_dump($add_tracking);
I need to restrict a category to a set of countries in Prestashop 1.5.
This restriction would prevent the shipping of a product belonging to such a category; as such, the users would still be able to see the products but they would not be able to buy them.
Ideally, I wanted to develop a module that would insert a list of countries (checkbox style, as in the Modules -> Payment page (AdminPayment)) inside a category's edit page, but I haven't been able to do so.
Why can't i simply paste the following code inside the renderForm() function?
Only the description is visible if i do so...
array(
'items' =>Country::getCountries(Context::getContext()->language->id),
'title' => $this->l('Country restrictions'),
'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want to block the shipping.'),
'name_id' => 'country',
'identifier' => 'id_country',
'icon' => 'world',
),
EDIT:
I managed to get the list of countries working:
array(
'type' => 'checkbox',
'label' => $this->l('Restricted Countries').':',
'class' => 'sel_country',
'name' => 'restricted_countries',
'values' => array(
'query' => Country::getCountries(Context::getContext()->language->id),
'id' => 'id_country',
'name' => 'name'
),
'desc' => $this->l('Mark all the countries you want to block the selling to. The restrictions will always be applied to every subcategory as well')
),
Now, I can save these values by checking if the value "submitAddcategory" is being submitted in the postProcess function and by running an insert query there. Similarly, I can also load the IDs of the blocked countries from the database, but how can I tick the respective select boxes in the list of countries?
My initial "quick and dirty" idea was to use jQuery selectors inside a document.ready(), but the code gets inserted before everything else and, as such, it won't work because jQuery isn't even loaded yet.
How can this be done?
Cheers
I solved it by using the following code right before the end of the renderForm() function.
The Pièce de résistance was $this->fields_value, as sadly I didn't known of its existence.
public function getRestrictedCountries($obj)
{
// Loading blacklisted countries
$country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT id_country
FROM `'._DB_PREFIX_.'category_country_restriction`
WHERE id_category = ' . (int)Tools::getValue('id_category') . ';');
$blacklisted_countries = array();
if (is_array($country))
foreach ($country as $cnt)
$blacklisted_countries[] = $cnt['id_country'];
// Global country list
$c_todos = Country::getCountries(Context::getContext()->language->id);
// Crossmatching everything
foreach ($c_todos as $c)
$this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries)));
}
PS: The table I am reading from is basically an associative table between 'category' and 'country'
I'm trying to integrate a cart-synchronisation-solution for my rest-clients.
The goal should be that I can have the same cart wherever I access my store from.
So I'll have to first of all deliver the existing items out to the client using the authenticated api-user.
But I get stuck at the very beginning:
protected function _retrieveCollection()
{
$cart = Mage::getSingleton('checkout/cart')->getQuote();
$cart->setCustomerId($this->getApiUser()->getUserId());
$cart->setStoreId(4);
$cart->load();
return $cart->getAllItems();
}
returns an empty array even though I have products in my cart.
Anyone any hints? Have that feeling I'm totally on the wrong side...
Found a solution. Getting the quote by Customer which is the other way around worked pretty well:
Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
$items[] = array(
'name' => $item->getName(),
'entity_id' => $item->getProductId(),
'description' => $item->getDescription(),
'final_price_with_tax' => $item->getBasePriceInclTax(),
'qty' => $item->getQty()
);
}