Problem with file and folder creation

I have moved a a local installation of shopkit (with a custom gateway) to my server for testing purposes. For some reason the online version is not able to create order folders and files when moving forward from the cart. Any idea why?

The order.create snippets forwards me correctly to the gateway, it just never creates the relevant files.

Wrong folder permissions?
Wrong folder owner group?

1 Like

I’ve moved this to a new topic, because it does not make sense to clutter the plugin thread with all sorts of questions that are more general in nature.

What should the folder permission be set too? 755? 777?

755 for folders (and some more characters)

Then it must be something else.

As far as I know the order.create.php snippet gets called, but the folder and .txt file never get created.

Here is the snippet:

// Honeypot trap for robots
if(r::is('post') and get('subject') != '') go(url('shop'));

$cart = Cart::getCart();
$country = get("country");

$shipping = 3.50;
if($cart->getAmount() < 50) {
    if($country == "Deutschland") {
            $shipping = 3.50;
        } else if($country != "Deutschland"){
            $shipping =  5.50;
        } 
} else {
    $shipping = 0;
};

$discount = getDiscount($cart);

// Set the timestamp so txn-id and txn-date use the same value
$timestamp = date('U');

// Create a YAML-structured list of products
$items = [];
foreach ($cart->getItems() as $i => $item) {
	$items[] = (array)$item;
}

// Unique transaction ID
$txn_id = get('gateway').'-'.$timestamp.'-'.bin2hex(openssl_random_pseudo_bytes(2));

try {
	// Create the pending order file
	page('shop/orders')->children()->create($txn_id, 'order', [
		'txn-id' => $txn_id,
		'txn-date'  => $timestamp,
		'txn-currency' => page('shop')->currency_code(),
		'status'  => 'pending',
		'stripe-charge-id' => 'stripe-charge-id',
		'token' => 'token',
		'products' => "\n".yaml::encode($items),
		'subtotal' => number_format($cart->getAmount(),2,'.',''),
		'discount' => number_format($discount['amount'],2,'.',''),
		'shipping' => number_format($shipping,2,'.',''),
		'tax' => number_format($cart->getTax(),2,'.',''),
		'giftcertificate' => null !== get('giftCertificateAmount') ? number_format(get('giftCertificateAmount'),2,'.','') : '0.00',
		'discountcode' => $discount['code'],
		'payer-id' => 'payer-id',
		'payment_method' => 'payment-method',
		'email' => 'email',
        'firstname' => 'firstname',
        'lastname' => 'lastname',
        'street' => 'street',
        'city' => 'city',
        'country' => $country
	]);
	
} catch(Exception $e) {
	// Order creation failed
	echo $e->getMessage();
}

// Redirect to self with GET, passing along the order ID
go('shop/cart/process/'.get('gateway').'/'.$txn_id);

Do you see anything in your Apache error log?

You can also check if the page is writable by logging the result of page('shop/orders')->isWritable() at the beginning of the snippet.

1 Like