Skip to content

Commit

Permalink
2.1.0 (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: AG <[email protected]>
  • Loading branch information
AJ9 and AG authored May 20, 2024
1 parent 7245b8f commit 7f42f87
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 31 deletions.
40 changes: 30 additions & 10 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,53 @@ jobs:
runs-on: macos-latest

steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Checkout
uses: actions/checkout@v2

- name: Set Default Scheme
run: |
scheme_list=$(xcodebuild -list -json | tr -d "\n")
default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
echo $default | cat >default
echo Using default scheme: $default
- name: Clean Build Folder
run: |
xcodebuild clean -scheme "gr4vy-ios" -alltargets
- name: Build
env:
scheme: gr4vy-ios
platform: ${{ 'iOS Simulator' }}
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}'`
device=$(xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}')
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
if [ "$(ls -A | grep -i \\.xcworkspace\$)" ]; then
filetype_parameter="workspace"
file_to_build="$(ls -A | grep -i \\.xcworkspace\$)"
else
filetype_parameter="project"
file_to_build="$(ls -A | grep -i \\.xcodeproj\$)"
fi
file_to_build=$(echo $file_to_build | awk '{$1=$1;print}')
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- name: Test
env:
scheme: gr4vy-iosTests
platform: ${{ 'iOS Simulator' }}
run: |
# xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}'`
device=$(xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}')
if [ $scheme = default ]; then scheme=$(cat default); fi
if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
xcodebuild test -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
if [ "$(ls -A | grep -i \\.xcworkspace\$)" ]; then
filetype_parameter="workspace"
file_to_build="$(ls -A | grep -i \\.xcworkspace\$)"
else
filetype_parameter="project"
file_to_build="$(ls -A | grep -i \\.xcodeproj\$)"
fi
file_to_build=$(echo $file_to_build | awk '{$1=$1;print}')
xcodebuild test -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=iOS Simulator,name=iPhone 15,OS=latest" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ gr4vy-ios doesn't contain any external dependencies.
use_frameworks!

target 'YOUR_TARGET_NAME' do
pod 'gr4vy-ios', '2.0.0'
pod 'gr4vy-ios', '2.1.0'
end
```

Expand Down Expand Up @@ -134,6 +134,7 @@ These are the parameteres available on the `launch` method:
| `cartItems` | `Optional` | An optional array of cart item objects, each object must define a `name`, `quantity`, and `unitAmount`.|
| `environment`| `Optional` | `.sandbox`, `.production`. Defaults to `.production`. When `.sandbox` is provided the URL will contain `sandbox.GR4VY_ID`. |
| `applePayMerchantId`| `Optional` | The Apple merchant ID to be used during Apple Pay transcations |
| `applePayMerchantName`| `Optional` | The name which appears in the Apple Pay dialog next to "Pay" |
| `theme`| `Optional` | Theme customisation options. See [Theming](https://github.com/gr4vy/gr4vy-embed/tree/main/packages/embed#theming). The iOS SDK also contains an additional two properties within the `colors` object; `headerBackground` and `headerText`. These are used for the navigation background and forground colors. |
| `buyerExternalIdentifier`| `Optional` | An optional external ID for a Gr4vy buyer. The transaction will automatically be associated to a buyer with that external ID. If no buyer with this external ID exists then it will be ignored. This option is ignored if the `buyerId` is provided. |
| `locale`| `Optional` | An optional locale, this consists of a `ISO 639 Language Code` followed by an optional `ISO 3166 Country Code`, e.g. `en`, `en-gb` or `pt-br`. |
Expand Down
10 changes: 6 additions & 4 deletions gr4vy-iOS/Gr4vy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class Gr4vy {
cartItems: [Gr4vyCartItem]? = nil,
environment: Gr4vyEnvironment = .production,
applePayMerchantId: String? = nil,
applePayMerchantName: String? = nil,
theme: Gr4vyTheme? = nil,
buyerExternalIdentifier: String? = nil,
locale: String? = nil,
Expand All @@ -75,6 +76,7 @@ public class Gr4vy {
paymentSource: paymentSource,
cartItems: cartItems,
applePayMerchantId: applePayMerchantId,
applePayMerchantName: applePayMerchantName,
theme: theme,
buyerExternalIdentifier: buyerExternalIdentifier,
locale: locale,
Expand Down Expand Up @@ -263,7 +265,7 @@ extension Gr4vy: Gr4vyInternalDelegate {
return
}

guard let request = handleAppleStartSession(message: message, merchantId: merchantId) else {
guard let request = handleAppleStartSession(message: message, merchantId: merchantId, merchantName: setup.applePayMerchantName) else {
error(message: "Gr4vy Error: Apple Pay session error")
return
}
Expand All @@ -284,8 +286,8 @@ extension Gr4vy: Gr4vyInternalDelegate {
}
}

func handleAppleStartSession(message: Gr4vyMessage, merchantId: String) -> PKPaymentRequest? {
return Gr4vyUtility.handleAppleStartSession(from: message.payload, merchantId: merchantId)
func handleAppleStartSession(message: Gr4vyMessage, merchantId: String, merchantName: String? = nil) -> PKPaymentRequest? {
return Gr4vyUtility.handleAppleStartSession(from: message.payload, merchantId: merchantId, merchantName: merchantName)
}

func generateApplePayAuthorized(payment: PKPayment) {
Expand Down Expand Up @@ -313,7 +315,7 @@ extension Gr4vy: Gr4vyInternalDelegate {

protocol Gr4vyInternalDelegate {
func handle(message: Gr4vyMessage, viewType: Gr4vyViewType)
func handleAppleStartSession(message: Gr4vyMessage, merchantId: String) -> PKPaymentRequest?
func handleAppleStartSession(message: Gr4vyMessage, merchantId: String, merchantName: String?) -> PKPaymentRequest?
func generateApplePayAuthorized(payment: PKPayment)
func handleAppleCancelSession()
func handleApprovalCancelled()
Expand Down
4 changes: 2 additions & 2 deletions gr4vy-iOS/Gr4vyUtility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ struct Gr4vyUtility {
return content
}

static func handleAppleStartSession(from payload: [String: Any], merchantId: String) -> PKPaymentRequest? {
static func handleAppleStartSession(from payload: [String: Any], merchantId: String, merchantName: String?) -> PKPaymentRequest? {
guard let data = payload["data"] as? [String: Any],
let countryCode = data["countryCode"] as? String,
let currencyCode = data["currencyCode"] as? String,
let total = data["total"] as? [String: Any],
let value = total["label"] as? String,
let value = merchantName ?? total["label"] as? String,
let amount = total["amount"] as? String else {
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion gr4vy-iOS/Models/Gr4vySetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct Gr4vySetup: Encodable {
var paymentSource: Gr4vyPaymentSource?
var cartItems: [Gr4vyCartItem]?
var applePayMerchantId: String?
var applePayMerchantName: String?
var theme: Gr4vyTheme?
var buyerExternalIdentifier: String?
var locale: String?
Expand Down Expand Up @@ -62,7 +63,7 @@ struct Gr4vySetup: Encodable {
case supportedApplePayVersion
}

public init(gr4vyId: String, token: String, amount: Int, currency: String, country: String, buyerId: String? = nil, environment: Gr4vyEnvironment, externalIdentifier: String? = nil, store: Gr4vyStore? = nil, display: String? = nil, intent: String? = nil, metadata: [String : String]? = nil, paymentSource: Gr4vyPaymentSource? = nil, cartItems: [Gr4vyCartItem]? = nil, applePayMerchantId: String? = nil, theme: Gr4vyTheme? = nil, buyerExternalIdentifier: String? = nil, locale: String? = nil, statementDescriptor: Gr4vyStatementDescriptor? = nil, requireSecurityCode: Bool? = nil, shippingDetailsId: String? = nil, merchantAccountId: String? = nil, connectionOptions: [String: [String: Gr4vyConnectionOptionsValue]]? = nil) {
public init(gr4vyId: String, token: String, amount: Int, currency: String, country: String, buyerId: String? = nil, environment: Gr4vyEnvironment, externalIdentifier: String? = nil, store: Gr4vyStore? = nil, display: String? = nil, intent: String? = nil, metadata: [String : String]? = nil, paymentSource: Gr4vyPaymentSource? = nil, cartItems: [Gr4vyCartItem]? = nil, applePayMerchantId: String? = nil, applePayMerchantName: String? = nil, theme: Gr4vyTheme? = nil, buyerExternalIdentifier: String? = nil, locale: String? = nil, statementDescriptor: Gr4vyStatementDescriptor? = nil, requireSecurityCode: Bool? = nil, shippingDetailsId: String? = nil, merchantAccountId: String? = nil, connectionOptions: [String: [String: Gr4vyConnectionOptionsValue]]? = nil) {
self.gr4vyId = gr4vyId
self.token = token
self.amount = amount
Expand All @@ -78,6 +79,7 @@ struct Gr4vySetup: Encodable {
self.paymentSource = paymentSource
self.cartItems = cartItems
self.applePayMerchantId = applePayMerchantId
self.applePayMerchantName = applePayMerchantName
self.theme = theme
self.buyerExternalIdentifier = buyerExternalIdentifier
self.locale = locale
Expand Down
52 changes: 40 additions & 12 deletions gr4vy-iOSTests/gr4vy_iOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,60 +748,88 @@ class gr4vy_iOSTests: XCTestCase {
var payload: [String: Any] = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]]
let merchantId: String = "merchantID"

var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNotNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNotNil(sut)

payload = ["data": ["supportedNetworks": ["VISA", "MASTERCARD"], "countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNotNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNotNil(sut)
}

func testHandleAppleStartFails() {
var payload: [String: Any] = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]]
let merchantId: String = "merchantID"

var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
var sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNotNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNotNil(sut)

payload = ["data": ["currencyCode": "currencyCode", "total": ["label": "label", "amount": "123"]]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)

payload = ["data": ["countryCode": "countryCode", "total": ["label": "label", "amount": "123"]]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)

payload = ["data": []]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)

payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode"]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)

payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["amount": "123"]]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNotNil(sut)

payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": ["label": "label"]]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)

payload = ["data": ["countryCode": "countryCode", "currencyCode": "currencyCode", "total": []]]

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId)
sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: nil)
XCTAssertNil(sut)

sut = Gr4vyUtility.handleAppleStartSession(from: payload, merchantId: merchantId, merchantName: "Test")
XCTAssertNil(sut)
}



func testGenerateAppleCompleteSessionSucceeds() {
let sut = Gr4vyUtility.generateAppleCompleteSession()
XCTAssertEqual("window.postMessage({ channel: 123, type: 'appleCompleteSession'})", sut)
Expand Down
2 changes: 1 addition & 1 deletion gr4vy-ios.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'gr4vy-ios'
s.version = '2.0.0'
s.version = '2.1.0'
s.license = 'MIT'
s.summary = 'Quickly embed Gr4vy in your iOS app to store card details, authorize payments, and capture a transaction.'
s.homepage = 'https://github.com/gr4vy/gr4vy-ios'
Expand Down

0 comments on commit 7f42f87

Please sign in to comment.