#include #include #include #include #include #include #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("PP Integration", 243, 110, 641, 307) GUICtrlCreateLabel("Client ID", 8, 18, 44, 17) $I_ClientID = GUICtrlCreateInput("", 72, 16, 161, 21) GUICtrlCreateLabel("Secret ID", 8, 42, 49, 17) $I_SecretID = GUICtrlCreateInput("", 72, 40, 161, 21) $B_PayNow = GUICtrlCreateButton("Pay Now", 8, 72, 75, 25) $B_Abort = GUICtrlCreateButton("Abort", 158, 72, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $sToken, $sOrderId, $ReqId Global $PPCounter = 0, $PPAbort = False ; # PRODUCT INFO Global $Currency = "EUR" Global $Price = "0.5" Global $product = "Test Product" Global $URL_Complete = "https://example.com/complete.php" Global $URL_Cancel = "https://example.com/cancel.php" ; # PRODUCT INFO While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $B_PayNow _PayPalProcess(GUICtrlRead($I_ClientID), GUICtrlRead($I_SecretID)) Case $B_Abort $PPAbort = True EndSwitch WEnd Func _PayPalProcess($ClientId, $SecretId) If $ClientId = "" And $SecretId = "" Then __CW("Fields can't be empty") Return EndIf $sToken = _PayPalGetToken($sURL, $EndPoint_GetToken, $ClientId, $SecretId) If $sToken = -1 Then __CW("Wrong credentials, check Client and Secret ID") Return EndIf $aReturn = _PaypalCreateOrder($sURL, $sToken, $EndPoint_Orders, $Currency, $Price, $product, "en-US", $URL_Complete, $URL_Cancel) $sOrderId = $aReturn[0] $ReqId = $aReturn[1] ShellExecute($aReturn[2]) __CW("Move to your browser to complete payment. AutoIt will wait 5 mins or until payment is processed. Press abort to cancel") AdlibRegister("_WaitPaypal",10000) EndFunc Func _WaitPaypal() $PPCounter += 1 Local $msg = _msg($PPCounter) If $PPCounter > 30 Or $PPAbort Then $PPCounter = 0 __CW("Paypal payment aborted") $PPAbort = False AdlibUnRegister("_WaitPaypal") Return Else __CW("[" & $msg & " minute/s passed] - " & "Waiting payment... (Press Abort to cancel)") EndIf $sOrderStatus = _PaypalOrderDetails($sToken, $EndPoint_Orders, $sOrderId) If $sOrderStatus = "APPROVED" Then __CW("Order approved, going to register purchase") $PPCounter = 0 $PPAbort = False AdlibUnRegister("_WaitPaypal") $FinalAnswer = _PaypalOrderCapture($sURL, $sToken, $EndPoint_Orders, $sOrderId, $ReqId) __CW("Final Answer: " & $FinalAnswer) Else __CW("Current Order Status: " & $sOrderStatus) EndIf EndFunc Func _msg($n) if $n >6 Then Return 1 if $n >12 Then Return 2 if $n >18 Then Return 3 if $n >24 Then Return 4 Return "Less than one" EndFunc