Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Speeter nspeet

View GitHub Profile
View timer.swift
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!")
}
View lineItemAdd.cs
// 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 Jul 26, 2019
HTTP request C#
View request.cs
// 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"
@nspeet
nspeet / .swift
Last active Jul 24, 2019
Cart Checkout
View .swift
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
View models3D.swift
//.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)
View applepay.swift
//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
@nspeet
nspeet / cartActionFlow.swift
Last active Feb 4, 2019
AR button action flow with Commercetools
View cartActionFlow.swift
// 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
}
....
@nspeet
nspeet / configSetup.swift
Last active Feb 4, 2019
Commercetools iOS Config Setup
View configSetup.swift
// 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