fix
This commit is contained in:
@@ -46,8 +46,10 @@ Paypal:
|
||||
|
||||
stripe:
|
||||
{
|
||||
publishable_key = "pk_test_X7TylEk9BkZCarcj0FyKRYXc";
|
||||
secret_key = "sk_test_MA2ltfGlT70Nu7uWlmHowBRB";
|
||||
publishable_key = "pk_test_51JwvOXCMmfol61TL2IlTEWytKObMLrZTAxJRHdepqWggXm4ENMyrrnR5dxfd5cPeflvCUG1HsErQI43BjOAmUEh500N0FWOZoE";
|
||||
old_publishable_key ="pk_test_X7TylEk9BkZCarcj0FyKRYXc";
|
||||
secret_key = "sk_test_51JwvOXCMmfol61TLadZlDf2rxq6Q1IC50JITRixcbyig8T2zdqpO8HY2NEcwNHacRQKQpTf6JGh7haqUVEH0rccA00eFht1ewi";
|
||||
old_secret_key = "sk_test_MA2ltfGlT70Nu7uWlmHowBRB";
|
||||
};
|
||||
|
||||
database:
|
||||
|
||||
@@ -9,5 +9,10 @@ long WrenchRefundoffer( CVars in, CVars &out );
|
||||
long WrenchContractPayment( CVars in, CVars &out );
|
||||
long WrenchCanceContractPayment( CVars in, CVars &out );
|
||||
|
||||
|
||||
long WrenchNewCardPayment( CVars in, CVars &out );
|
||||
long WrenchCardRechargePayment( CVars in, CVars &out );
|
||||
long CheckWallet(long member_id,CVars in);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -167,6 +167,12 @@ enum { PARTNER_STRIPE };
|
||||
#define WRENCHBOARD_USER_SENDMONEY 11051
|
||||
#define WRENCHBOARD_USER_SENDJOBINT 11052
|
||||
|
||||
#define WRENCHBOARD_USER_ADNEWCC 11054
|
||||
#define WRENCHBOARD_USER_USESAVEDCC 11056
|
||||
|
||||
#define WRENCHBOARD_ACCOUNT_WALLETS 11060
|
||||
|
||||
|
||||
#define WRENCHBOARD_ACCOUNT_END 11999
|
||||
//**************************************************************
|
||||
#define WRENCHBOARD_GROUP_START 12000
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <curl/curl.h>
|
||||
#include "smoney.h"
|
||||
#include "account_mngt.h"
|
||||
#include "creditcards.h"
|
||||
#include "payments.h"
|
||||
|
||||
#include "jobs.h"
|
||||
|
||||
@@ -294,18 +296,29 @@ test();
|
||||
return WrenchLoadDashData(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_GETBANKLIST:
|
||||
return WrenchReturnMemberBankAccount(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_SENDMONEY:
|
||||
return WrenchBoardMobileSendMoney(in, out);
|
||||
case WRENCHBOARD_USER_GETBANKLIST:
|
||||
return WrenchReturnMemberBankAccount(in, out);
|
||||
break;
|
||||
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_SENDJOBINT:
|
||||
return WrenchBoardMobileSendJobInterest(in, out);
|
||||
break;
|
||||
case WRENCHBOARD_USER_SENDMONEY:
|
||||
return WrenchBoardMobileSendMoney(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_SENDJOBINT:
|
||||
return WrenchBoardMobileSendJobInterest(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_ADNEWCC:
|
||||
return WrenchNewCardPayment(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_USER_USESAVEDCC:
|
||||
return WrenchCardRechargePayment(in, out);
|
||||
break;
|
||||
|
||||
case WRENCHBOARD_ACCOUNT_WALLETS:
|
||||
logfmt(logINFO, "/account_calls()");
|
||||
break;
|
||||
|
||||
}
|
||||
logfmt(logINFO, "/account_calls()");
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "pgsql_wrapper.h"
|
||||
#include "cfg.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include "payments.h"
|
||||
#include "account.h"
|
||||
|
||||
|
||||
@@ -514,6 +514,12 @@ long CreateWrenchBoardAccount(CVars in, CVars &out) {
|
||||
x["member_id"].set_valid(true);
|
||||
x["pending_id"] = out["pending_id"];
|
||||
x["pending_id"].set_valid(true);
|
||||
|
||||
CVars vw;
|
||||
vw["currency"] = "NAIRA"; // this will become a variable based on the country
|
||||
vw["currency"].set_valid( true );
|
||||
out["wallet_id"] = CheckWallet(out["member_id"].Long(),vw); // initial wallet
|
||||
|
||||
// - password already set pgsql_query("UPDATE members SET password = md5('%s') WHERE id = %lu",in["pass1"].c_str(),ret);
|
||||
pgsql_query("UPDATE members_pending SET status = 5 WHERE id = %lu", out["pending_id"].Long());
|
||||
pgsql_query("UPDATE members_refer_friend SET status = 5 WHERE status = 1 AND email = '%s'", x["email"].c_str());
|
||||
|
||||
@@ -22,14 +22,14 @@ long save_creditcard(CVars in, CVars &out) {
|
||||
try {
|
||||
CVars v;
|
||||
|
||||
REQ_LONG(in, "member_id", 1, -1); // Does not make any sence without member persitence
|
||||
REQ_LONG(in, "member_id", 1, -1); // Does not make any sence without member persitence
|
||||
REQ_STRING(in, "cardnumber", 12, 16, "(.*)"); //4111111111111111"
|
||||
REQ_STRING(in, "cvc", 3, 4, "(.*)"); //234"
|
||||
REQ_LONG(in, "paymenttype", 0, -1);
|
||||
REQ_STRING(in, "exp_month", 2, 2, "(.*)");
|
||||
REQ_STRING(in, "exp_year", 4, 4, "(.*)");
|
||||
|
||||
if ( load_db_record( v, "SELECT a.id AS member_id,a.firstname,a.lastname,'' AS street1,'' AS street2,a.city,'' AS postal,a.state,a.country FROM members a WHERE a.id=%lu", in["member_id"].Long()) > 0) {
|
||||
if ( load_db_record( v, "SELECT a.id AS member_id,a.firstname,a.lastname,'' AS street1,'' AS street2,a.city,zip_code AS postal,a.state,a.country FROM members a WHERE a.id=%lu", in["member_id"].Long()) > 0) {
|
||||
|
||||
logfmt(logDEBUG, "Loaded member %s %s", v["firstname"].c_str(), v["lastname"].c_str());
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "input.h"
|
||||
#include "wrenchboard_api.h"
|
||||
#include "payments.h"
|
||||
#include "creditcards.h"
|
||||
#include "common_tool.h"
|
||||
#include "email.h"
|
||||
#include "safestring.h"
|
||||
@@ -28,6 +29,167 @@ INSERT INTO payment_types(type_code,code,dir) VALUES('OFFER_PYM_DEPOSIT','OFDPS'
|
||||
INSERT INTO payment_types(type_code,code,dir) VALUES('OFFER_PYM_REFUND','OFRFD',1); -- // refund if offer was rejected or not accepted
|
||||
*/
|
||||
|
||||
long UpdateMemberWallet(long member_id,long wallet_id,long amount, long payment_id);
|
||||
|
||||
/*
|
||||
call to verify the user have the wallet in place - or create it
|
||||
if this fail , dont continue with collecting money , no place to put it.
|
||||
*/
|
||||
long CheckWallet(long member_id,CVars in){
|
||||
logfmt(FLOG_MAX, "long CheckWallet()" );
|
||||
long wallet_id = 0;
|
||||
CVars y;
|
||||
if ( load_db_record( y, "SELECT * FROM members_wallet WHERE currency ='%s' AND member_id =%lu",in["currency"].c_str(),member_id ) > 0 )
|
||||
{
|
||||
wallet_id = y["id"].Long();
|
||||
}
|
||||
else{
|
||||
|
||||
CVars x;
|
||||
x["member_id"] = member_id; x["member_id"].set_valid( true );
|
||||
x["currency"] = in["currency"]; x["currency"].set_valid( true );
|
||||
wallet_id = insert_db_record( DBS_VALID, "members_wallet", "members_wallet_id_seq", x );
|
||||
}
|
||||
return wallet_id;
|
||||
}
|
||||
|
||||
long UpdateMemberWallet(long member_id,long wallet_id,long amount, long payment_id){
|
||||
CVars y;
|
||||
if ( load_db_record( y, "SELECT * FROM members_wallet WHERE id = %lu AND member_id =%lu", wallet_id,member_id ) > 0 )
|
||||
{
|
||||
|
||||
CVars x;
|
||||
x["member_id"] = member_id; x["member_id"].set_valid( true ); //
|
||||
x["payment_id"] = payment_id; x["payment_id"].set_valid( true ); //
|
||||
x["amount"] = amount; x["amount"].set_valid( true ); //
|
||||
x["balance"] = y["amount"]; x["balance"].set_valid( true ); //
|
||||
insert_db_record( DBS_VALID, "members_wallet_detail", "members_wallet_detail_id_seq", x );
|
||||
|
||||
|
||||
pgsql_exec("UPDATE members_wallet SET amount=amount + %lu,prev_amount=%lu WHERE member_id = %lu AND id=%lu",amount,y["amount"].Long(),member_id , wallet_id); // pay attention to who you pay here
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
long WrenchNewCardPayment( CVars in, CVars &out )
|
||||
{
|
||||
long payment_return = 0; // just return 0 if not okay , payment_id is all okay
|
||||
logfmt(FLOG_MAX, "long WrenchNewCardPayment(CVars in, CVars &out)" );
|
||||
long member_id = REQ_LONG( in, "member_id", 1, -1 );
|
||||
long amount = REQ_LONG( in, "amount", 1, -1 );
|
||||
OPTIONAL(in, "WHAT_CHARGE_TYPE") REQ_STRING(in, "WHAT_CHARGE_TYPE", 3, 15, "(.*)");
|
||||
long card_id = 0;
|
||||
|
||||
if ( in["WHAT_CHARGE_TYPE"] == "USE_CARD_ID"){
|
||||
card_id = REQ_LONG( in, "card_id", 1, -1 );
|
||||
in["what_purhcase"] = "MEMBER_RETCARD_PAYM"; in["what_purhcase"].set_valid( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
REQ_STRING(in, "cardnumber", 12, 16, "(.*)"); //4111111111111111"
|
||||
REQ_STRING(in, "cvc", 3, 4, "(.*)"); //234"
|
||||
REQ_LONG(in, "paymenttype", 0, -1);
|
||||
REQ_STRING(in, "exp_month", 2, 2, "(.*)");
|
||||
REQ_STRING(in, "exp_year", 4, 4, "(.*)");
|
||||
in["what_purhcase"] = "MEMBER_NEWCARD_PAYM"; in["what_purhcase"].set_valid( true );
|
||||
}
|
||||
|
||||
|
||||
const char * loc = getenv("REMOTE_ADDR");
|
||||
in["loc"] = loc; in["loc"].set_valid(true);
|
||||
|
||||
long payment_id =0;
|
||||
|
||||
// do we have a wallet for this action
|
||||
CVars vw;
|
||||
vw["currency"] = "USD"; // this might become a variable based on the country
|
||||
vw["currency"].set_valid( true );
|
||||
long wallet_id = CheckWallet(member_id,vw);
|
||||
if(!wallet_id || wallet_id == 0 ){
|
||||
return -1; // no wallet
|
||||
}
|
||||
in["curr_balance"] ="0";
|
||||
long retDb = load_db_record( out, "SELECT amount AS curr_balance FROM members_wallet WHERE member_id = %lu AND currency='%s' ", member_id, vw["currency"].c_str());
|
||||
if (retDb)
|
||||
{ in["curr_balance"] =out["curr_balance"]; in["curr_balance"].set_valid( true );
|
||||
logfmt(FLOG_MAX, "Current balance Read ********************" );
|
||||
}
|
||||
else { return -1; /* unable to read wallet*/ }
|
||||
|
||||
// verify if allowed
|
||||
|
||||
// take in sessionid to verify if allaowed too
|
||||
|
||||
// Get the code and dir contruct
|
||||
long retTc = load_db_record( out, "SELECT * FROM payment_types WHERE type_code = '%s' ",in["what_purhcase"].c_str());
|
||||
if (retTc)
|
||||
{
|
||||
in["code"] = out["code"]; in["code"].set_valid( true );
|
||||
in["dir"] = out["dir"]; in["dir"].set_valid( true );
|
||||
}
|
||||
else { return -1; /* unable to get payment type*/ }
|
||||
|
||||
CVars x;
|
||||
x["member_id"] = member_id; x["member_id"].set_valid( true ); //
|
||||
x["loc"] = in["loc"]; x["loc"].set_valid( true ); //
|
||||
x["curr_balance"] = in["curr_balance"]; x["curr_balance"].set_valid( true ); //
|
||||
x["amount"] = amount; x["amount"].set_valid( true );
|
||||
x["fee"] = "0"; x["fee"].set_valid( true );
|
||||
x["code"] = in["code"]; x["code"].set_valid( true );
|
||||
x["dir"] = in["dir"]; x["dir"].set_valid( true );
|
||||
x["flags"] = FLAG_INIT; x["flags"].set_valid( true ); // starting the pprocess
|
||||
x["currency"] = vw["currency"]; x["currency"].set_valid( true );
|
||||
|
||||
payment_id = insert_db_record( DBS_VALID, "members_payments", "members_payments_id_seq", x );
|
||||
// ALL STRIPE COMPATIBLE
|
||||
if ( card_id == 0 ){
|
||||
card_id = save_creditcard(in, out);
|
||||
}
|
||||
|
||||
|
||||
if (card_id && card_id> 0){
|
||||
pgsql_exec("UPDATE members_payments SET account_id = %lu WHERE id = %lu",card_id,payment_id );
|
||||
}
|
||||
else{
|
||||
return -1;
|
||||
}
|
||||
|
||||
CVars yx;
|
||||
yx["member_id"] = member_id; yx["member_id"].set_valid( true );
|
||||
yx["payment_id"] = payment_id; yx["payment_id"].set_valid( true );
|
||||
long stripe_payment = stripe_charge_member_paymentid(yx, out); // go for stripe now
|
||||
|
||||
if (stripe_payment==PHP_API_OK) {
|
||||
x["flags"] = FLAG_START; x["flags"].set_valid( true ); // done not completed yet
|
||||
//pgsql_exec("UPDATE members_wallet SET amount=amount + %lu,prev_amount=%lu WHERE member_id = %lu AND id=%lu",x["amount"].Long(),x["curr_balance"].Long(),x["member_id"].Long() , wallet_id); // pay attention to who you pay here
|
||||
|
||||
char confirmation[15] = "";
|
||||
Confirmation(payment_id, confirmation, sizeof (confirmation)); // this stamp the offer code directly in that call
|
||||
UpdateMemberWallet( member_id, wallet_id,x["amount"].Long(), payment_id); // correct this dont send amount
|
||||
x["flags"] = FLAG_OK; x["flags"].set_valid( true );
|
||||
x["payment_id"] = payment_id; x["payment_id"].set_valid( true );
|
||||
pgsql_exec("UPDATE members_payments SET flags = %lu WHERE id = %lu",x["flags"].Long(),payment_id );
|
||||
load_db_record( out, "SELECT * FROM members_payments WHERE id = %lu ", payment_id );
|
||||
payment_return = payment_id;
|
||||
} else {
|
||||
out["status"] = "Unable to create payment";
|
||||
}
|
||||
|
||||
logfmt(FLOG_MAX, "/long WrenchNewCardPayment(CVars in, CVars &out)" );
|
||||
return payment_return;
|
||||
}
|
||||
|
||||
long WrenchCardRechargePayment( CVars in, CVars &out )
|
||||
{
|
||||
logfmt(FLOG_MAX, "long WrenchCardRechargePayment(CVars in, CVars &out)" );
|
||||
long member_id = REQ_LONG( in, "member_id", 1, -1 );
|
||||
long amount = REQ_LONG( in, "amount", 1, -1 );
|
||||
long card_id = REQ_LONG( in, "card_id", 1, -1 );
|
||||
in["WHAT_CHARGE_TYPE"] = "USE_CARD_ID"; in["WHAT_CHARGE_TYPE"].set_valid( true ); //
|
||||
return WrenchNewCardPayment( in, out );
|
||||
logfmt(FLOG_MAX, "/long WrenchCardRechargePayment(CVars in, CVars &out)" );
|
||||
}
|
||||
|
||||
long WrenchCanceContractPayment( CVars in, CVars &out )
|
||||
{
|
||||
|
||||
|
||||
@@ -294,10 +294,9 @@ long stripe_charge_member_paymentid(CVars in, CVars &out) {
|
||||
logfmt(logINFO, "stripe_charge_member_paymentid()");
|
||||
out["result"] = "stripe_charge_member_paymentid() call in progress...";
|
||||
long res, ret = PHP_API_BAD_PARAM;
|
||||
|
||||
|
||||
try {
|
||||
REQ_LONG(in, "service_id", 0, -1);
|
||||
// REQ_LONG(in, "service_id", 0, -1);
|
||||
// REQ_LONG(in, "payment_id", 0, -1);
|
||||
REQ_LONG(in, "member_id", 0, -1);
|
||||
long payment_id = REQ_LONG(in, "payment_id", 0, -1);
|
||||
|
||||
@@ -318,7 +317,7 @@ long stripe_charge_member_paymentid(CVars in, CVars &out) {
|
||||
return ret;
|
||||
}
|
||||
*/
|
||||
in["description"] = "Laundry Pickup";
|
||||
in["description"] = "Account Recharge";
|
||||
in["invoice_id"] = in["payment_id"];
|
||||
|
||||
|
||||
@@ -350,7 +349,10 @@ long stripe_charge_member_paymentid(CVars in, CVars &out) {
|
||||
ret = PHP_API_OK;
|
||||
out["id"] = id;
|
||||
pgsql_exec("UPDATE members_payments SET stripe_confirm='%s',dt_confirmed=now() WHERE id = %lu", id, payment_id);
|
||||
//pgsql_exec("UPDATE members_service_request SET payment_id=%lu,dt_confirmed=now(),flags=%lu WHERE id = %lu",payment_id, CONFIRMED , in["service_id"].Long());
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
out["result"] = "Charge success";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user