My code for paypal sdk is like below
func makePaypalPayment(amount:String,userEmail:String,eChitthiAmount:String) {
Checkout.start(
createOrder: { createOrderAction in
// This order is for eChitthi
let amountForeChitthi = PurchaseUnit.Amount(currencyCode: .usd, value: eChitthiAmount)
let purchaseUnitForeChitthi = PurchaseUnit(amount: amountForeChitthi)
// This order is for user
let amount = PurchaseUnit.Amount(currencyCode: .usd, value: amount)
let payeeDetail = PurchaseUnit.Payee(emailAddress:userEmail)
let purchaseUnit = PurchaseUnit(amount: amount,payee: payeeDetail)
let order : OrderRequest = OrderRequest(intent: .capture, purchaseUnits: [purchaseUnit,purchaseUnitForeChitthi])
createOrderAction.create(order: order)
}, onApprove: { approval in
approval.actions.capture { (response, error) in
print("Payment successfully")
}
}, onCancel: {
print("Order is cancelled.")
}, one rror: { error in
print("Order have some error.")
}
)
}
Here I want to make two transaction for one payment. Like user want to transfer $100 to his friend then 1% charge will be gone to application's owner.
So I my scenario If userA want to transfer $100 to userB then total amount $101 will be cut from userA's paypal account and $100 will goes to userB's account and $1 goes to application's owner account. For that I created two PurchaseUnit object and passed both into OrderRequest. Because of that getting The operation couldn’t be completed. (OrderActionError error 202.)
I am using SDK : PayPalCheckout (0.73.0)
Language : Swift
Help (I have implemented code from this document) - https://developer.paypal.com/docs/business/native-checkout/ios/programmatically-start-sdk/
Any help will be appreciate. Thanks.
CodePudding user response:
When specifying multiple purchase_units in an orders creation request, each must have a unique reference_id
, as they are independent payments and may succeed or fail individually. They will also result in independent PayPal transactions.
This is documented at https://developer.paypal.com/docs/api/orders/v2/#orders-create-request-body