Skip to content

Added Apple Pay for checkout block payment #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions assets/js/blocks-apple-pay.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { useEffect, useRef } from '@wordpress/element'

const Shift4ApplePay = ({ onClick, onClose, onSubmit, billing }) => {
Expand Down Expand Up @@ -46,7 +45,7 @@ const Shift4ApplePay = ({ onClick, onClose, onSubmit, billing }) => {

try {
const applePayToken = await window.shift4PayWithApplePay({
value: cartTotal.value,
value: (cartTotal.value / Math.pow(10, currency.minorUnit)).toFixed(currency.minorUnit),
currency: currency.code
})

Expand Down
24 changes: 11 additions & 13 deletions assets/js/blocks.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
const { registerPaymentMethod } = window.wc.wcBlocksRegistry
// const { registerExpressPaymentMethod } = window.wc.wcBlocksRegistry
const { createElement } = window.wp.element
const { registerExpressPaymentMethod } = window.wc.wcBlocksRegistry
const { cardTitle, savedCardsEnabled } = window.shift4Config

import React from 'react'
import Shift4PaymentForm from './blocks-form'
// import Shift4ApplePay from './blocks-apple-pay'
import Shift4ApplePay from './blocks-apple-pay'

// Register Shift4 Apple Pay.
// registerExpressPaymentMethod({
// name: 'shift4_applepay',
// label: 'Apple Pay (Shift4)',
// edit: <p>Apple Pay (Shift4)</p>,
// content: <Shift4ApplePay />,
// canMakePayment: () => {
// return !!(window.ApplePaySession && window.ApplePaySession.canMakePayments())
// }
// })
registerExpressPaymentMethod({
name: 'shift4_applepay',
label: 'Apple Pay (Shift4)',
edit: <p>Apple Pay (Shift4)</p>,
content: <Shift4ApplePay />,
canMakePayment: () => {
return !!(window.ApplePaySession && window.ApplePaySession.canMakePayments())
}
})

// Register Shift4 Credit Card.
registerPaymentMethod({
Expand Down
2 changes: 1 addition & 1 deletion build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.