-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
P-2021-12-29:User_Interface->Payment_And_Calendar
- Loading branch information
Marzouq Almukhlif
authored and
Marzouq Almukhlif
committed
Dec 29, 2021
1 parent
1c184bd
commit f36eb50
Showing
12 changed files
with
1,085 additions
and
1,175 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
mudaris/Mudaris/Controllers/InvoiceController+MFSDKServicesCall.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// | ||
// ViewController+MFSDKServicesCall.swift | ||
// MFSDKDemo-Swift | ||
// | ||
// Created by Elsayed Hussein on 8/29/19. | ||
// Copyright © 2019 Elsayed Hussein. All rights reserved. | ||
// | ||
|
||
import MFSDK | ||
|
||
extension InvoiceController { | ||
func initiatePayment() { | ||
payButton.isEnabled = false | ||
let request = generateInitiatePaymentModel() | ||
// startLoading() | ||
MFPaymentRequest.shared.initiatePayment(request: request, apiLanguage: .arabic, completion: { [weak self] (result) in | ||
// self?.stopLoading() | ||
switch result { | ||
case .success(let initiatePaymentResponse): | ||
self?.paymentMethods = initiatePaymentResponse.paymentMethods | ||
self?.collectionView.reloadData() | ||
case .failure(let failError): | ||
// self?.showFailError(failError) | ||
print("") | ||
} | ||
}) | ||
} | ||
|
||
|
||
func executeApplePayPayment(paymentMethodId: Int) { | ||
let request = getExecutePaymentRequest(paymentMethodId: paymentMethodId) | ||
if #available(iOS 13.0, *) { | ||
MFPaymentRequest.shared.executeApplePayPayment(request: request, apiLanguage: .arabic) { (response, invoiceId) in | ||
switch response { | ||
case .success(let executePaymentResponse): | ||
if let invoiceStatus = executePaymentResponse.invoiceStatus { | ||
print("showSuccess1 \(invoiceStatus)") | ||
self.dismiss(animated: true, completion: nil) | ||
} | ||
case .failure(let failError): | ||
self.dismiss(animated: true, completion: nil) | ||
print("showFailError1 \(failError.errorDescription)") | ||
} | ||
} | ||
} else { | ||
MFPaymentRequest.shared.executeApplePayPayment(request: request, apiLanguage: .arabic) { response, invoiceId in | ||
switch response { | ||
case .success(let executePaymentResponse): | ||
if let invoiceStatus = executePaymentResponse.invoiceStatus { | ||
self.dismiss(animated: true, completion: nil) | ||
print("showSuccess2 \(invoiceStatus)") | ||
} | ||
case .failure(let failError): | ||
self.dismiss(animated: true, completion: nil) | ||
print("showFailError2 \(failError.errorDescription)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
func executePayment(paymentMethodId: Int) { | ||
let request = getExecutePaymentRequest(paymentMethodId: paymentMethodId) | ||
MFPaymentRequest.shared.executePayment(request: request, apiLanguage: .arabic) { response, invoiceId in | ||
switch response { | ||
case .success(let executePaymentResponse): | ||
if let invoiceStatus = executePaymentResponse.invoiceStatus { | ||
print("showSuccess3 \(invoiceStatus)") | ||
self.performSegue(withIdentifier: "showMain", sender: nil) | ||
|
||
// DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(30)) { | ||
// self.dismiss(animated: true, completion: nil) | ||
// } | ||
|
||
} | ||
case .failure(let failError): | ||
print("showFailError3 \(failError.errorDescription)") | ||
self.dismiss(animated: true, completion: nil) | ||
|
||
} | ||
} | ||
} | ||
|
||
|
||
func sendPayment() { | ||
let request = getSendPaymentRequest() | ||
MFPaymentRequest.shared.sendPayment(request: request, apiLanguage: .arabic) { [weak self] (result) in | ||
switch result { | ||
case .success(let sendPaymentResponse): | ||
if let invoiceURL = sendPaymentResponse.invoiceURL { | ||
// self?.errorCodeLabel.text = "Success" | ||
// self?.resultTextView.text = "result: send this link to your customers \(invoiceURL)" | ||
} | ||
case .failure(let failError): | ||
// self?.showFailError(failError) | ||
print("showFailError \(failError.errorDescription)") | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
private func generateInitiatePaymentModel() -> MFInitiatePaymentRequest { | ||
let request = MFInitiatePaymentRequest() | ||
return request | ||
} | ||
|
||
|
||
|
||
//// PAY | ||
private func getExecutePaymentRequest(paymentMethodId: Int) -> MFExecutePaymentRequest { | ||
let request = MFExecutePaymentRequest(invoiceValue: invoiceValue , paymentMethod: paymentMethodId) | ||
request.customerEmail = "[email protected]"// must be email | ||
request.customerMobile = "112233" | ||
request.customerName = "Test MyFatoorah" | ||
let address = MFCustomerAddress(block: "ddd", street: "sss", houseBuildingNo: "sss", address: "sss", addressInstructions: "sss") | ||
request.customerAddress = address | ||
request.language = .arabic | ||
request.mobileCountryCode = MFMobileCountryCodeISO.saudiArabia.rawValue | ||
request.displayCurrencyIso = .saudiArabia_SAR | ||
return request | ||
} | ||
|
||
|
||
|
||
func getSendPaymentRequest() -> MFSendPaymentRequest { | ||
// let invoiceValue = Decimal(string: amountTextField.text ?? "") ?? 0 | ||
let request = MFSendPaymentRequest(invoiceValue: invoiceValue, notificationOption: .all, customerName: "Test") | ||
|
||
//request.userDefinedField = "" | ||
request.customerEmail = "[email protected]"// must be email | ||
request.customerMobile = "mobile no"//Required | ||
request.customerCivilId = "" | ||
request.mobileCountryIsoCode = MFMobileCountryCodeISO.saudiArabia.rawValue | ||
request.customerReference = "" | ||
request.language = .arabic | ||
let address = MFCustomerAddress(block: "ddd", street: "sss", houseBuildingNo: "sss", address: "sss", addressInstructions: "sss") | ||
request.customerAddress = address | ||
request.language = .arabic | ||
request.displayCurrencyIso = .saudiArabia_SAR | ||
let date = Date().addingTimeInterval(1000) | ||
request.expiryDate = date | ||
return request | ||
} | ||
|
||
|
||
} | ||
|
Oops, something went wrong.