Skip to content
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

Add WeChat Pay payment method (v4.27.0) #259

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
116 changes: 67 additions & 49 deletions ExampleApp/Resources/Main.storyboard

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions ExampleApp/Shared/PaymentSettingTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class PaymentSettingTableViewController: UITableViewController {
@IBOutlet private var maybankQRPayPaymentCell: UITableViewCell!
@IBOutlet private var duitNowQRPaymentCell: UITableViewCell!
@IBOutlet private var duitNowOBWPaymentCell: UITableViewCell!
@IBOutlet private var weChatPaymentCell: UITableViewCell!
@IBOutlet private var useCapabilityAPIValuesCell: UITableViewCell!
@IBOutlet private var useSpecifiedValuesCell: UITableViewCell!

Expand Down Expand Up @@ -354,6 +355,8 @@ extension PaymentSettingTableViewController {
return .duitNowQR
case duitNowOBWPaymentCell:
return .duitNowOBW
case weChatPaymentCell:
return .weChat
default:
return nil
}
Expand Down Expand Up @@ -448,6 +451,8 @@ extension PaymentSettingTableViewController {
return duitNowQRPaymentCell
case .duitNowOBW:
return duitNowOBWPaymentCell
case .weChat:
return weChatPaymentCell
default:
return nil
}
Expand Down
9 changes: 8 additions & 1 deletion OmiseSDK/Capability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ extension Capability {
case duitNowQR
case duitNowOBW
case payPay
case weChat
case unknownSource(String, configurations: [String: Any])
}

Expand Down Expand Up @@ -183,6 +184,8 @@ extension Capability.Backend.Payment {
return true
case (.payPay, .payPay):
return true
case (.weChat, .weChat):
return true
default:
return false
}
Expand Down Expand Up @@ -317,6 +320,8 @@ extension Capability.Backend {
self.payment = .duitNowOBW
case .source(.payPay):
self.payment = .payPay
case .source(.weChat):
self.payment = .weChat
case .source(let value):
let configurations = try container.decodeJSONDictionary()
self.payment = .unknownSource(value.rawValue, configurations: configurations)
Expand All @@ -337,7 +342,7 @@ extension Capability.Backend {
case .installment(_, availableNumberOfTerms: let availableNumberOfTerms):
try container.encode(Array(availableNumberOfTerms), forKey: .allowedInstallmentTerms)
try container.encode(Array(supportedCurrencies), forKey: .supportedCurrencies)
case .internetBanking, .alipay, .alipayCN, .alipayHK, .atome, .dana, .gcash, .kakaoPay, .touchNGoAlipayPlus, .touchNGo, .promptpay, .paynow, .truemoney, .truemoneyJumpApp, .points, .billPayment, .eContext, .mobileBanking, .fpx, .rabbitLinepay, .ocbcPao, .ocbcDigital, .grabPay, .grabPayRms, .boost, .shopeePay, .shopeePayJumpApp, .maybankQRPay, .duitNowQR, .duitNowOBW, .payPay:
case .internetBanking, .alipay, .alipayCN, .alipayHK, .atome, .dana, .gcash, .kakaoPay, .touchNGoAlipayPlus, .touchNGo, .promptpay, .paynow, .truemoney, .truemoneyJumpApp, .points, .billPayment, .eContext, .mobileBanking, .fpx, .rabbitLinepay, .ocbcPao, .ocbcDigital, .grabPay, .grabPayRms, .boost, .shopeePay, .shopeePayJumpApp, .maybankQRPay, .duitNowQR, .duitNowOBW, .payPay, .weChat:
// swiftlint:disable:previous line_length
try container.encode(Array(supportedCurrencies), forKey: .supportedCurrencies)
case .unknownSource(_, configurations: let configurations):
Expand Down Expand Up @@ -445,6 +450,8 @@ extension Capability.Backend {
self = .source(.duitNowOBW)
case .payPay:
self = .source(.payPay)
case .weChat:
self = .source(.weChat)
case .unknownSource(let sourceType, configurations: _):
self = .source(.init(sourceType))
}
Expand Down
7 changes: 6 additions & 1 deletion OmiseSDK/Compatibility/OmiseCapability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public class __OmiseCapabilitySourceBackendPayment: __OmiseCapabilityBackendPaym
__OmiseCapabilitySourceBackendPayment(sourceType: OMSSourceTypeValue.duitNowOBW)

static let payPaySourceBackendPayment =
__OmiseCapabilitySourceBackendPayment(sourceType: OMSSourceTypeValue.payPay)
__OmiseCapabilitySourceBackendPayment(sourceType: OMSSourceTypeValue.payPay)

static let weChatSourceBackendPayment =
__OmiseCapabilitySourceBackendPayment(sourceType: OMSSourceTypeValue.weChat)

static func makeInternetBankingSourceBackendPayment(
bank: PaymentInformation.InternetBanking
Expand Down Expand Up @@ -235,6 +238,8 @@ extension __OmiseCapabilityBackendPayment {
return __OmiseCapabilitySourceBackendPayment.duitNowOBWSourceBackendPayment
case .payPay:
return __OmiseCapabilitySourceBackendPayment.payPaySourceBackendPayment
case .weChat:
return __OmiseCapabilitySourceBackendPayment.weChatSourceBackendPayment
case .unknownSource(let type, let configurations):
return __OmiseCapabilityUnknownSourceBackendPayment(sourceType: type, parameters: configurations)
}
Expand Down
8 changes: 7 additions & 1 deletion OmiseSDK/Compatibility/OmiseSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public class __SourcePaymentInformation: NSObject {
/// Payment Information for a PayPay Payment
public static let paypayPayment = __SourcePaymentInformation(type: OMSSourceTypeValue.payPay)!

/// Payment Information for a PayPay Payment
public static let weChatPayment = __SourcePaymentInformation(type: OMSSourceTypeValue.weChat)!

/// Payment Information for an Truemoney JumpApp
public static let truemoneyJumpAppPayment = __SourcePaymentInformation(type: OMSSourceTypeValue.trueMoneyJumpApp)!
}
Expand Down Expand Up @@ -684,7 +687,10 @@ extension __SourcePaymentInformation {

case .duitNowOBW(let duitNowOBW):
return __SourceDuitNowOBWPayment(bank: duitNowOBW.bank)


case .weChat:
return __SourcePaymentInformation.weChatPayment

case .other(type: let type, parameters: let parameters):
return __CustomSourcePayment(customType: type, parameters: parameters)
}
Expand Down
2 changes: 2 additions & 0 deletions OmiseSDK/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ extension OMSSourceTypeValue {
return "duitnow_obw"
case .payPay:
return "paypay"
case .weChat:
return "wechat_pay"
default:
return self.rawValue
}
Expand Down
11 changes: 11 additions & 0 deletions OmiseSDK/PaymentChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum PaymentChooserOption: CaseIterable, Equatable, CustomStringConvertible {
case touchNGo
case grabPayRms
case payPay
case weChat

var description: String {
switch self {
Expand Down Expand Up @@ -111,6 +112,8 @@ enum PaymentChooserOption: CaseIterable, Equatable, CustomStringConvertible {
return "GrabPay"
case .payPay:
return "PayPay"
case .weChat:
return "WeChat"
}
}
}
Expand Down Expand Up @@ -186,6 +189,8 @@ extension PaymentChooserOption {
return [.duitNowOBW]
case .payPay:
return [.payPay]
case .weChat:
return [.weChat]
default:
return []
}
Expand Down Expand Up @@ -365,6 +370,8 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
return
case .truemoneyJumpApp:
payment = .truemoneyJumpApp
case .weChat:
payment = .weChat
default:
return
}
Expand Down Expand Up @@ -461,6 +468,8 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
return IndexPath(row: 32, section: 0)
case .truemoneyJumpApp:
return IndexPath(row: 33, section: 0)
case .weChat:
return IndexPath(row: 34, section: 0)
}
}

Expand Down Expand Up @@ -543,6 +552,8 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
return OMSSourceTypeValue.duitNowOBW
case .payPay:
return OMSSourceTypeValue.payPay
case .weChat:
return OMSSourceTypeValue.weChat
case .card, .unknownSource:
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions OmiseSDK/PaymentInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ public enum PaymentInformation: Codable, Equatable {
/// PayNow Payment Source
case paynow

/// WeChat Payment Source
case weChat

/// The TrueMoney customer information
public struct TrueMoney: PaymentMethod {

Expand Down Expand Up @@ -525,6 +528,9 @@ public enum PaymentInformation: Codable, Equatable {
case .payPay:
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(OMSSourceTypeValue.payPay.rawValue, forKey: .type)
case .weChat:
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(OMSSourceTypeValue.weChat.rawValue, forKey: .type)
case .other(type: let type, parameters: let parameters):
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(type, forKey: .type)
Expand Down Expand Up @@ -591,6 +597,8 @@ public enum PaymentInformation: Codable, Equatable {
return lhsValue == rhsValue
case (.payPay, .payPay):
return true
case (.weChat, .weChat):
return true
case (.other(let lhsType, let lhsParameters), .other(let rhsType, let rhsParameters)):
return lhsType == rhsType &&
Set(lhsParameters.keys) == Set(rhsParameters.keys)
Expand Down Expand Up @@ -675,6 +683,8 @@ extension PaymentInformation {
return bank.type
case .payPay:
return OMSSourceTypeValue.payPay.rawValue
case .weChat:
return OMSSourceTypeValue.weChat.rawValue
case .other(let value, _):
return value
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "wechat_pay.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading