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();
Related
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.
I am trying to setup a payment processor using omnipay-authorizenet AuthorizeNet_CIM. Not a lot of documentation on this.
Step 1) I create the gateway object successfully and can make requests to the authorize.net sandbox server.
Step 2) is to "create a card" for future use with Token Billing: $gateway->createCard() . This is successful.
From the General Omnipay Token Billing documentation:
"... createCard($options) - returns a response object which includes a cardReference, which can be used for future transactions..."
I don't see a specific 'cardReference' in the above createCard() response object.
So I create a $cardRef array and grab the returned response CustomerProfileId and CustomerPaymentProfileId .
$profileResult['customerProfileId']=$response->getCustomerProfileId();
$profileResult['paymentProfileId']=$response->getCustomerPaymentProfileId();
Step 3) is a function to generate the purchase which fails:
function create_transaction($cardRef,$amount,$description,$invoice_number){
global $status, $gateway;
try {
// Send purchase request
$response = $gateway->purchase(
array(
'cardReference' => $cardRef ,
'amount' => $amount,
'currency' => 'USD',
'description' => $_POST['description'],
'transactionId' => $invoice_number
)
)->send();
if ($response->isSuccessful()) {
// Payment was successful
$status.='Success: '.$response->getMessage();
} elseif ($response->isRedirect()) {
// Redirect to offsite payment gateway
$response->redirect();
} else {
// Payment failed
$status.='Transaction Failure: '.$response->getMessage();
}
} catch (Exception $e) {
$status.='<strong>Error:</strong> '.$e->getMessage(). "<br/>";
}
}
The purchase fails and when I look at the Response object it seems the Request is not populating the cardReference object.
[cardReference] => Omnipay\AuthorizeNet\Model\CardReference Object
(
[customerProfileId:Omnipay\AuthorizeNet\Model\CardReference:private] =>
[paymentProfileId:Omnipay\AuthorizeNet\Model\CardReference:private] =>
[shippingProfileId:Omnipay\AuthorizeNet\Model\CardReference:private] =>
)
I am obviously not passing the correct cardReference data to the purchase method.
Any help would be greatly appreciated.
Thanks
I apparently needed to use the undocumented Omnipay method;
$response->getCardReference();
to get a cardReference object to pass to my create_transaction() function.
All fixed.
Thanks
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'm trying to implement the PayPal API function for SetExpressCheckout. Below I put a part of my code that I am using to call the payment process on the PayPal side. Everything looks fine. At the last step of the checkout, i push the "Pay Now" button and the payment is processed. After that user is returnet to my original site and i got the Transaction ID, success message and token. It looks like evrything was finished fine, but in my PayPal account i dont see any transactions and I don’t get any money at all.
$returnUrl = home_url("/wp-login.php?checkemail=registered&ppayment=done&price=".$package_price."&code=".$paypal_price_unit."&package=".$package_name."&pid=".$incomingpost);
$requestParams = array(
'RETURNURL' => $returnUrl,
'CANCELURL' => home_url('/wp-login.php?checkemail=registered&ppayment=cancel')
);
// Sent item info
$orderParams = array(
'PAYMENTREQUEST_0_AMT' => $package_price,
'PAYMENTREQUEST_0_SHIPPINGAMT' => '0',
'PAYMENTREQUEST_0_CURRENCYCODE' => $paypal_price_unit,
'PAYMENTREQUEST_0_ITEMAMT' => $package_price
);
//send package info
$item = array(
'L_PAYMENTREQUEST_0_NAME0' => $paymentName,
'L_PAYMENTREQUEST_0_DESC0' => $package_name,
'L_PAYMENTREQUEST_0_AMT0' => $package_price,
'L_PAYMENTREQUEST_0_QTY0' => '1'
);
//Call payment process
$infos = array();
$infos['USER'] = $paypal_api_user;
$infos['PWD'] = $paypal_api_pwd;
$infos['SIGNATURE'] = $paypal_api_signature;
if($paypal_sandbox == 1){$sandstatus = true;}else{$sandstatus = false;}
$paypal = new Paypal($infos,$sandstatus);
$response = $paypal -> request('SetExpressCheckout',$requestParams + $orderParams + $item);
if(is_array($response) && $response['ACK'] == 'Success') {
// We will redirecting now.
$token = $response['TOKEN'];
//Save DB before redirect.
$trans_post = array(
'post_status' => 'pending',
'post_type' => 'retransactions',
'post_title' => $token,
);
$new_post_id = wp_insert_post( $trans_post );
add_post_meta($new_post_id, 'webburemap_payment_user', $user_id);
add_post_meta($new_post_id, 'webburemap_payment_amount', $package_price);
add_post_meta($new_post_id, 'webburemap_payment_package_id', $package_IDNO);
add_post_meta($new_post_id, 'webburemap_payment_package_transtype', 'NewPackage');
if($paypal_sandbox == 0){
$commit = '&useraction=commit';
header( 'Location: https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) . $commit ); //PayPal Pay Now
}else{
header( 'Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
}
die();
}
Can you provide the Express Checkout Token and the Transaction ID that you are getting back and I will take a look at it on my side to see what may be happening. Also make sure that you are pointing to the correct endpoint. If you are trying to process a live payment, make sure you are pointing towards the live site and not the sandbox.