Skip to content

Instantly share code, notes, and snippets.

View Ninigi's full-sized avatar

Fabian Zitter Ninigi

View GitHub Profile

Keybase proof

I hereby claim:

  • I am ninigi on github.
  • I am fabianz (https://keybase.io/fabianz) on keybase.
  • I have a public key ASA-8HonGp7KrJPhHF1PNEyx1r0pH-Mf_GKKrNQpmU3h9wo

To claim this, I am signing this object:

@Ninigi
Ninigi / hide_and_show.js
Last active March 23, 2020 08:04
How to hide and show payment gateways in shopify checkout (COD)
// The Payment Gateway / Shippnig Method can be internationalized,
// if the shop does not use this internationalization, use ["Cash on Delivery (COD)"]
var CODGatewayNames = ["代金引換", "Cash on Delivery (COD)"],
CODShippingNames = ["代金引換", "Cash on Delivery"],
radioButtonSelector = ".radio__input .input-radio";
function toggleCODPayment(shippingElement) {
var isCOD = function(el) {
var label = el.querySelectorAll(".radio__label__primary")[0];
var labelText = label ? label.textContent.trim().toLowerCase() : "";
function toggleCountryPayment() {
var isPayPal = function(el) {
return el.querySelectorAll(".radio__label__primary")[0] && el.querySelectorAll(".radio__label__primary")[0].textContent.trim() === "PayPal";
}
var shipToElement = document.querySelector("address.address") && document.querySelector("address.address").firstChild;
if (shipToElement && shipToElement.data.indexOf("Malaysia") > -1) {
var els = document.querySelectorAll(".section--payment-method .radio-wrapper.content-box__row"),
radioButtons = [];
defmodule Useless.Plugs.EmbeddedAppPlug do
@moduledoc """
Loads the shop from database, puts a private shop field in conn and sets x-frame-options.
Will halt if no shop found
"""
alias Plug.Conn
alias Useless.ShopifyApp
defmodule UselessWeb.ShopController do
# ...
def new(conn, %{"hmac" => _, "shop" => shopify_domain}) do
shop = ShopifyApp.find_shop_by(%{shopify_domain: shopify_domain})
conn
|> put_layout({UselessWeb.EmbeddedAppView, "layout.html"})
|> render("show.html", shop: shop)
end
defmodule UselessWeb.ShopController do
# ...
def new(conn, %{"shop" => shop_name}) when is_bitstring(shop_name),
do: signup(conn, %{"shop" => %{"shopify_domain" => shop_name}})
def new(conn, _params) do
changeset = ShopifyApp.change_shop(%Shop{})
render(conn, "new.html", changeset: changeset)
end
defmodule UselessWeb.AuthController do
use UselessWeb, :controller
alias Useless.ShopifyApp
alias Useless.ShopifyApp.Shop
def shopify(conn, %{"shop" => shopify_domain, "code" => shopify_token}) do
session = shopify_domain |> Shopify.session()
with {:ok, %{data: oauth}} <- Shopify.OAuth.request_token(session, shopify_token),
defmodule UselessWeb.ShopController do
use UselessWeb, :controller
alias Useless.ShopifyApp
alias Useless.ShopifyApp.Shop
def new(conn, _params) do
changeset = ShopifyApp.change_shop(%Shop{})
render(conn, "new.html", changeset: changeset)
end
@doc """
Creates a new shop if no shop with the given shopify_domain exists, or updates
the existing shop
## Examples
iex> create_or_update_shop(%{shopify_domain: "shop@my_shopify.com", shopify_token: "a-token"})
{:ok, %Shop{}}
iex> create_or_update_shop(%{shopify_domain: nil, shopify_token: "a-token"})
test "create_or_update_shop/1 creates a shop if it doesn't already exist" do
assert {:ok, %Shop{} = shop} = ShopifyApp.create_or_update_shop(@valid_attrs)
assert shop.shopify_domain == @valid_attrs.shopify_domain
assert shop.shopify_token == @valid_attrs.shopify_token
end
test "create_or_update_shop/1 updates a shop's token if it already exists" do
shop_fixture()
params = %{
shopify_domain: @valid_attrs.shopify_domain,