Skip to content

Instantly share code, notes, and snippets.

View nspeet's full-sized avatar

Nick Speeter nspeet

View GitHub Profile
@nspeet
nspeet / configSetup.swift
Last active February 4, 2019 14:52
Commercetools iOS Config Setup
// Add the code below to viewDidLoad()
// Default configuration initializer reads from
// CommercetoolsConfig.plist file from your app bundle
if let configuration = Config() {
// You can also specify custom logging level
// configuration.logLevel = .error
// Or completely disable all log messages from Commercetools SDK
// configuration.loggingEnabled = false
// Finally, you need set your configuration before using the SDK
Commercetools.config = configuration
@nspeet
nspeet / cartActionFlow.swift
Last active February 4, 2019 15:18
AR button action flow with Commercetools
// Step 1. create a menu button to select products
// Then on this menu button click... search for products, you can set a filter as required
ProductProjection.search(sort: ["name.en asc"], limit: 10, lang: Locale(identifier: "en"), { result in
if let response = result.model, let total = response.total as? UInt,
let results = response.results as? Array<ProductProjection>, result.isSuccess {
//handle showing results
}
....
//1. Check if the PKPaymentAuthorizationViewController can make payments
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) {
// develop your payment request
let request = PKPaymentRequest()
request.merchantIdentifier = "merchant.yourmerchantid" //add more info to the payment request as needed
//2. Then present the Apple Pay authorizationViewController
let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request)
if let viewController = authorizationViewController {
viewController.delegate = self
//.dae file
var object3D: SCNNode!
let chair = SCNScene(named: "art.scnassets/furniture/chair/bag-chair.dae")
object3D = chair?.rootNode;
self.object.removeFromParentNode()
self.object = object3D;
//.obj file
let url = URL.init(string: "https://3D2348.com/couch.obj")
let entity = MDLAsset(url: url)
@nspeet
nspeet / .swift
Last active July 24, 2019 19:45
Cart Checkout
Cart.active(result: { result in
if let cart = result.model, result.isSuccess {
// Cart successfully retrieved, response contains currently active cart
Cart.byId(cart.id, result: { result in
if let cart = result.model, result.isSuccess {
// successfully retrieved current cart
let draftOrder = OrderDraft(id: cart.id, version: cart.version);
Order.create(draftOrder, result: { result in
if let order = result.model, result.isSuccess {
// order successfully created, response contains updated order
// add line item to Cart
using (var client = new HttpClient())
{
// assembledEndpoint: {{host}}/{{projectKey}}/me/carts/cartId
var endpoint = assembledEndpoint;
var body = new Dictionary<string, string>
{
{ "version", "1" },
{ "actions": [{
"action": "addLineItem",
@nspeet
nspeet / request.cs
Last active July 26, 2019 15:32
HTTP request C#
// Create Cart
using (var client = new HttpClient())
{
// assembledEndpoint: {{host}}/{{projectKey}}/me/carts
var endpoint = assembledEndpoint;
var body = new Dictionary<string, string>
{
{ "currency", "USD" },
{ "shippingAddress", {
"country": "US"
let timer = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(updateData), userInfo: nil, repeats: true)
@objc func updateData() {
print("update data here and then display!")
}